Skip to content

Commit 47abb15

Browse files
minnieliuMinnie Liusacheun
authored
[Communication] - Administration - Identity API Redesign (Azure#18614)
* Initial commit * Completing administration client APIs * Rename identity to user * AccessToken renane * Add generated code from latest identity swagger * Add java doc * Use old types and rename accessToken to Token * Regenerate code from latest swagger and fix all compilation errors * Extract Identity code to its package * Remove phone number in README.md * Add checkstyle supression for identity package * Remove unnecessary files * Address PR feedback * Address PR feedback * Rename Identities to Identity in generated code * Adding client implementation and async tests * Adding Identity tests * Adding Identity tests * Adding all redacted tests and updated documents * Cleanup changes * Addresing code review comments and removing custom token class * Fixing version * Fix build * Update Chat recorded tests * Revert pom * Fix build * Fix tests * scope identity package to tests for chat package Co-authored-by: Minnie Liu <peiliu@microsoft.com> Co-authored-by: sacheu <sacheu@microsoft.com>
1 parent 8401d88 commit 47abb15

File tree

168 files changed

+6293
-5108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+6293
-5108
lines changed

eng/.docsettings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ known_content_issues:
127127
- ['sdk/communication/azure-communication-chat/swagger/README.md', '#3113']
128128
- ['sdk/communication/azure-communication-sms/swagger/README.md', '#3113']
129129
- ['sdk/communication/azure-communication-administration/swagger/README.md', '#3113']
130+
- ['sdk/communication/azure-communication-identity/swagger/README.md', '#3113']
130131
- ['sdk/cosmos/changelog/README.md', '#3113']
131132
- ['sdk/cosmos/faq/README.md', '#3113']
132133
- ['sdk/cosmos/azure-cosmos-benchmark/README.md', '#3113']

eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ the main ServiceBusClientBuilder. -->
396396
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicyCheck"
397397
files="com.azure.communication.common.implementation.HmacAuthenticationPolicy.java"/>
398398
<suppress checks="[a-zA-Z0-9]*" files="com.azure.data.schemaregistry.implementation.*"/>
399+
<suppress checks="com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck" files="com.azure.communication.administration.implementation.CommunicationIdentityImpl.java"/>
400+
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" files="com.azure.communication.identity.CommunicationIdentityClient.java"/>
401+
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" files="com.azure.communication.identity.CommunicationIdentityAsyncClient.java"/>
399402

400403
<!-- Suppress the check on synapse code-gen classes -->
401404
<suppress checks="Indentation" files="com.azure.analytics.synapse.accesscontrol.implementation..*ClientImpl" />

eng/versioning/version_client.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ com.azure:azure-communication-chat;1.0.0-beta.3;1.0.0-beta.4
4949
com.azure:azure-communication-common;1.0.0-beta.3;1.0.0-beta.4
5050
com.azure:azure-communication-administration;1.0.0-beta.3;1.0.0-beta.4
5151
com.azure:azure-communication-sms;1.0.0-beta.3;1.0.0-beta.4
52+
com.azure:azure-communication-identity;1.0.0-beta.4;1.0.0-beta.4
5253
com.azure:azure-core;1.12.0;1.13.0-beta.1
5354
com.azure:azure-core-amqp;2.0.1;2.1.0-beta.1
5455
com.azure:azure-core-amqp-experimental;1.0.0-beta.1;1.0.0-beta.1

sdk/communication/azure-communication-administration/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Release History
22

33
## 1.0.0-beta.4 (Unreleased)
4-
- Added support for Azure Active Directory Authentication for both clients.
4+
### Added
5+
- Added support for Azure Active Directory Authentication.
6+
7+
### Breaking Changes
8+
- CommunicationIdentityClient and CommunicationIdentityAsyncClient is moved to a new package, `azure-communication-identity`.
59

610
## 1.0.0-beta.3 (2020-11-16)
711
### Added

sdk/communication/azure-communication-administration/README.md

Lines changed: 13 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Azure Communication Administration client library for Java
22

3-
The administration package is used for managing users and tokens for Azure Communication Services. This package also provides capabilities for Phone Number Administration.
3+
The administration package provides capabilities for Phone Number Administration.
44

55
Acquired phone numbers can come with many capabilities, depending on the country, number type and phone plan. Examples of capabilities are SMS inbound and outbound usage, PSTN inbound and outbound usage. Phone numbers can also be assigned to a bot via a webhook URL.
66

@@ -28,69 +28,10 @@ Acquired phone numbers can come with many capabilities, depending on the country
2828

2929
## Key concepts
3030

31-
There are two forms of authentication to use the Administration SDK:
3231

33-
### Azure Active Directory Token Authentication
34-
A `DefaultAzureCredential` object must be passed to the `CommunicationIdentityClientBuilder` or
35-
`PhoneNumberClientBuilder` via the credential() funtion. Endpoint and httpClient must also be set
36-
via the endpoint() and httpClient() functions respectively.
37-
38-
`AZURE_CLIENT_SECRET`, `AZURE_CLIENT_ID` and `AZURE_TENANT_ID` environment variables
39-
are needed to create a DefaultAzureCredential object.
40-
41-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L377-L389 -->
42-
```java
43-
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";
44-
45-
// Create an HttpClient builder of your choice and customize it
46-
HttpClient httpClient = new NettyAsyncHttpClientBuilder().build();
47-
48-
CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClientBuilder()
49-
.endpoint(endpoint)
50-
.credential(new DefaultAzureCredentialBuilder().build())
51-
.httpClient(httpClient)
52-
.buildClient();
53-
54-
return communicationIdentityClient;
55-
}
56-
```
57-
58-
### Access Key Authentication
59-
Administration uses HMAC authentication with the resource access key.
60-
The access key must be provided to the `CommunicationIdentityClientBuilder`
61-
or the `PhoneNumberClientBuilder` via the accessKey() function. Endpoint and httpClient must also be set
62-
via the endpoint() and httpClient() functions respectively.
63-
64-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L37-L48 -->
65-
```java
66-
// You can find your endpoint and access key from your resource in the Azure Portal
67-
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";
68-
String accessKey = "SECRET";
69-
70-
// Create an HttpClient builder of your choice and customize it
71-
HttpClient httpClient = new NettyAsyncHttpClientBuilder().build();
72-
73-
CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClientBuilder()
74-
.endpoint(endpoint)
75-
.accessKey(accessKey)
76-
.httpClient(httpClient)
77-
.buildClient();
78-
```
79-
80-
Alternatively, you can provide the entire connection string using the connectionString() function instead of providing the endpoint and access key.
81-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L62-L68 -->
82-
```java
83-
// Your can find your connection string from your resource in the Azure Portal
84-
String connectionString = "<connection_string>";
85-
86-
CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClientBuilder()
87-
.connectionString(connectionString)
88-
.httpClient(httpClient)
89-
.buildClient();
90-
```
9132
### Initializing Phone Number Client
92-
As it was mentioned before, the PhoneNumberClientBuilder is also enabled to use Azure Active Directory Authentication
93-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L398-L407 -->
33+
The PhoneNumberClientBuilder is enabled to use Azure Active Directory Authentication
34+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L285-L294 -->
9435
```java
9536
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";
9637

@@ -105,7 +46,7 @@ PhoneNumberClient phoneNumberClient = new PhoneNumberClientBuilder()
10546
```
10647

10748
Using the endpoint and access key from the communication resource to authenticate is also posible.
108-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L128-L139 -->
49+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L36-L47 -->
10950
```java
11051
// You can find your endpoint and access token from your resource in the Azure Portal
11152
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";
@@ -138,52 +79,9 @@ Phone numbers can be assigned to a callback URL via the configure number API. As
13879

13980
## Examples
14081

141-
### Creating a new user
142-
Use the `createUser` function to create a new user. `user.getId()` gets the
143-
unique ID of the user that was created.
144-
145-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L80-L81 -->
146-
```java
147-
CommunicationUserIdentifier user = communicationIdentityClient.createUser();
148-
System.out.println("User id: " + user.getId());
149-
```
150-
151-
### Issuing or Refreshing a token for an existing user
152-
Use the `issueToken` function to issue or refresh a token for an existing user. The function
153-
also takes in a list of communication token scopes. Scope options include:
154-
- `chat` (Chat)
155-
- `pstn` (Public switched telephone network)
156-
- `voip` (Voice over IP)
157-
158-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L93-L96 -->
159-
```java
160-
List<String> scopes = new ArrayList<>(Arrays.asList("chat"));
161-
CommunicationUserToken userToken = communicationIdentityClient.issueToken(user, scopes);
162-
System.out.println("Token: " + userToken.getToken());
163-
System.out.println("Expires On: " + userToken.getExpiresOn());
164-
```
165-
166-
### Revoking all tokens for an existing user
167-
Use the `revokeTokens` function to revoke all the issued tokens of a user.
168-
169-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L108-L109 -->
170-
```java
171-
// revoke tokens issued for the user prior to now
172-
communicationIdentityClient.revokeTokens(user, OffsetDateTime.now());
173-
```
174-
175-
### Deleting a user
176-
Use the `deleteUser` function to delete a user.
177-
178-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L118-L119 -->
179-
```java
180-
// delete a previously created user
181-
communicationIdentityClient.deleteUser(user);
182-
```
183-
18482
### Get Countries
18583

186-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L151-L160 -->
84+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L59-L68 -->
18785
```java
18886
PhoneNumberClient phoneNumberClient = createPhoneNumberClient();
18987

@@ -201,10 +99,8 @@ for (PhoneNumberCountry phoneNumberCountry
20199

202100
Phone plan groups come in two types, Geographic and Toll-Free.
203101

204-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L193-L202 -->
102+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L103-L110 -->
205103
```java
206-
PhoneNumberClient phoneNumberClient = createPhoneNumberClient();
207-
208104
PagedIterable<PhonePlanGroup> phonePlanGroups = phoneNumberClient
209105
.listPhonePlanGroups(countryCode, locale, true);
210106

@@ -219,10 +115,8 @@ for (PhonePlanGroup phonePlanGroup
219115

220116
Unlike Toll-Free phone plans, area codes for Geographic Phone Plans are empty. Area codes are found in the Area Codes API.
221117

222-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L216-L227 -->
118+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L126-L135 -->
223119
```java
224-
PhoneNumberClient phoneNumberClient = createPhoneNumberClient();
225-
226120
PagedIterable<PhonePlan> phonePlans = phoneNumberClient
227121
.listPhonePlans(countryCode, phonePlanGroupId, locale);
228122

@@ -239,10 +133,8 @@ for (PhonePlan phonePlan
239133

240134
For Geographic phone plans, you can query the available geographic locations. The locations options are structured like the geographic hierarchy of a country. For example, the US has states and within each state are cities.
241135

242-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L242-L260 -->
136+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L152-L168 -->
243137
```java
244-
PhoneNumberClient phoneNumberClient = createPhoneNumberClient();
245-
246138
LocationOptions locationOptions = phoneNumberClient
247139
.getPhonePlanLocationOptions(countryCode, phonePlanGroupId, phonePlanId, locale)
248140
.getLocationOptions();
@@ -266,10 +158,8 @@ for (LocationOptionsDetails locationOptionsDetails
266158

267159
Fetching area codes for geographic phone plans will require the the location options queries set. You must include the chain of geographic locations traversing down the location options object returned by the GetLocationOptions API.
268160

269-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L284-L292 -->
161+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L194-L200 -->
270162
```java
271-
PhoneNumberClient phoneNumberClient = createPhoneNumberClient();
272-
273163
AreaCodes areaCodes = phoneNumberClient
274164
.getAllAreaCodes("selection", countryCode, phonePlanId, locationOptions);
275165

@@ -281,7 +171,7 @@ for (String areaCode
281171

282172
### Configure Phone Number
283173

284-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L306-L306 -->
174+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L214-L214 -->
285175
```java
286176
phoneNumberClient.configureNumber(phoneNumber, pstnConfiguration);
287177
```
@@ -292,7 +182,7 @@ The Phone Number Client supports a variety of long running operations that allow
292182

293183
### Create Search
294184

295-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L313-L337 -->
185+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L221-L245 -->
296186
```java
297187
String phonePlanId = "PHONE_PLAN_ID";
298188

@@ -322,7 +212,7 @@ for (String phoneNumber: result.getPhoneNumbers()) {
322212
```
323213

324214
### Purchase Search
325-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L344-L350 -->
215+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L252-L258 -->
326216
```java
327217
Duration duration = Duration.ofSeconds(1);
328218
String phoneNumberReservationId = "RESERVATION_ID_TO_PURCHASE";
@@ -334,7 +224,7 @@ res.waitForCompletion();
334224
```
335225

336226
### Release Phone Numbers
337-
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L357-L367 -->
227+
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L265-L275 -->
338228
```java
339229
Duration duration = Duration.ofSeconds(1);
340230
PhoneNumberIdentifier phoneNumber = new PhoneNumberIdentifier("PHONE_NUMBER_TO_RELEASE");

sdk/communication/azure-communication-administration/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<properties>
5050
<src.dir>src/main</src.dir>
5151
<test.dir>src/test</test.dir>
52-
<jacoco.min.linecoverage>0.75</jacoco.min.linecoverage>
52+
<jacoco.min.linecoverage>0.70</jacoco.min.linecoverage>
5353
<jacoco.min.branchcoverage>0.55</jacoco.min.branchcoverage>
5454
</properties>
5555

0 commit comments

Comments
 (0)