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
55Acquired 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
9536String endpoint = " https://<RESOURCE_NAME>.communication.azure.com" ;
9637
@@ -105,7 +46,7 @@ PhoneNumberClient phoneNumberClient = new PhoneNumberClientBuilder()
10546```
10647
10748Using 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
11152String 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
18886PhoneNumberClient phoneNumberClient = createPhoneNumberClient();
18987
@@ -201,10 +99,8 @@ for (PhoneNumberCountry phoneNumberCountry
20199
202100Phone 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-
208104PagedIterable<PhonePlanGroup > phonePlanGroups = phoneNumberClient
209105 .listPhonePlanGroups(countryCode, locale, true );
210106
@@ -219,10 +115,8 @@ for (PhonePlanGroup phonePlanGroup
219115
220116Unlike 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-
226120PagedIterable<PhonePlan > phonePlans = phoneNumberClient
227121 .listPhonePlans(countryCode, phonePlanGroupId, locale);
228122
@@ -239,10 +133,8 @@ for (PhonePlan phonePlan
239133
240134For 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-
246138LocationOptions locationOptions = phoneNumberClient
247139 .getPhonePlanLocationOptions(countryCode, phonePlanGroupId, phonePlanId, locale)
248140 .getLocationOptions();
@@ -266,10 +158,8 @@ for (LocationOptionsDetails locationOptionsDetails
266158
267159Fetching 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-
273163AreaCodes 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
286176phoneNumberClient. 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
297187String 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
327217Duration duration = Duration . ofSeconds(1 );
328218String 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
339229Duration duration = Duration . ofSeconds(1 );
340230PhoneNumberIdentifier phoneNumber = new PhoneNumberIdentifier (" PHONE_NUMBER_TO_RELEASE" );
0 commit comments