Skip to content

Commit 1f9a96d

Browse files
authored
Merge pull request #180326 from ProbablePrime/rifox/editorial-token-quickstart
Editorial pass of access tokens quick start
2 parents f9f656e + 07efc79 commit 1f9a96d

File tree

5 files changed

+117
-89
lines changed

5 files changed

+117
-89
lines changed

articles/communication-services/quickstarts/access-tokens.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ manager: nmurav
77
services: azure-communication-services
88

99
ms.author: tchladek
10-
ms.date: 06/30/2021
10+
ms.date: 11/17/2021
1111
ms.topic: quickstart
1212
ms.service: azure-communication-services
1313
ms.subservice: identity
@@ -16,24 +16,26 @@ zone_pivot_groups: acs-js-csharp-java-python
1616

1717
# Quickstart: Create and manage access tokens
1818

19-
Get started with Azure Communication Services by using the Communication Services Identity SDK. It allows you to create identities and manage your access tokens. Identity is representing entity of your application in the Azure Communication Service (for example, user or device). Access tokens let your Chat and Calling SDKs authenticate directly against Azure Communication Services. We recommend generating access tokens on a server-side service. Access tokens are then used to initialize the Communication Services SDKs on client devices.
19+
Access tokens let ACS SDKs [authenticate](../concepts/authentication.md) directly against Azure Communication Services as a particular identity. You'll need to create some if you want your users to join a call or chat thread within your application.
20+
21+
You can also use the ACS SDKs to create identities and manage your access tokens and in this quickstart we'll be learning how to do this. For production use cases we recommend generating access tokens on a [server-side service](../concepts/client-and-server-architecture.md).
2022

2123
Any prices seen in images throughout this tutorial are for demonstration purposes only.
2224

2325
::: zone pivot="programming-language-csharp"
24-
[!INCLUDE [.NET](./includes/user-access-token-net.md)]
26+
[!INCLUDE [.NET](./includes/access-tokens/access-token-net.md)]
2527
::: zone-end
2628

2729
::: zone pivot="programming-language-javascript"
28-
[!INCLUDE [JavaScript](./includes/user-access-token-js.md)]
30+
[!INCLUDE [JavaScript](./includes/access-tokens/access-token-js.md)]
2931
::: zone-end
3032

3133
::: zone pivot="programming-language-python"
32-
[!INCLUDE [Python](./includes/user-access-token-python.md)]
34+
[!INCLUDE [Python](./includes/access-tokens/access-token-python.md)]
3335
::: zone-end
3436

3537
::: zone pivot="programming-language-java"
36-
[!INCLUDE [Java](./includes/user-access-token-java.md)]
38+
[!INCLUDE [Java](./includes/access-tokens/access-token-java.md)]
3739
::: zone-end
3840

3941
The output of the app describes each action that is completed:

articles/communication-services/quickstarts/includes/user-access-token-java.md renamed to articles/communication-services/quickstarts/includes/access-tokens/access-token-java.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ author: tomaschladek
66
manager: nmurav
77
ms.service: azure-communication-services
88
ms.subservice: azure-communication-services
9-
ms.date: 06/30/2021
9+
ms.date: 11/17/2021
1010
ms.topic: include
1111
ms.custom: include file
1212
ms.author: tchladek
1313
---
1414

15-
> [!NOTE]
16-
> Find the finalized code for this quickstart on [GitHub](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/access-token-quickstart)
17-
1815
## Prerequisites
1916

2017
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
2118
- [Java Development Kit (JDK)](/azure/developer/java/fundamentals/java-jdk-install) version 8 or above.
2219
- [Apache Maven](https://maven.apache.org/download.cgi).
23-
- A deployed Communication Services resource and connection string. [Create a Communication Services resource](../create-communication-resource.md).
20+
- A deployed Communication Services resource and connection string. [Create a Communication Services resource](../../create-communication-resource.md).
21+
22+
## Final Code
23+
Find the finalized code for this quickstart on [GitHub](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/access-token-quickstart).
2424

2525
## Setting Up
2626

@@ -32,9 +32,9 @@ Open your terminal or command window. Navigate to the directory where you'd like
3232
mvn archetype:generate -DgroupId=com.communication.quickstart -DartifactId=communication-quickstart -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
3333
```
3434

35-
You'll notice that the 'generate' task created a directory with the same name as the `artifactId`. Under this directory, the src/main/java directory contains the project source code, the `src/test/java directory` contains the test source, and the `pom.xml` file is the project's Project Object Model, or POM.
35+
You'll notice that the 'generate' task created a directory with the same name as the `artifactId`. Under this directory, the src/main/java directory contains the project source code, the `src/test/java directory` contains the test source, and the `pom.xml` file is the project's Project Object Model, or POM. This file is used for project configuration parameters.
3636

37-
### Install the package
37+
### Install the ACS packages
3838

3939
Open the **pom.xml** file in your text editor. Add the following dependency element to the group of dependencies.
4040

@@ -46,12 +46,14 @@ Open the **pom.xml** file in your text editor. Add the following dependency elem
4646
</dependency>
4747
```
4848

49+
This will instruct Maven to install the ACS Identity SDK when we use it later on.
50+
4951
### Set up the app framework
5052

5153
From the project directory:
5254

53-
1. Navigate to the */src/main/java/com/communication/quickstart* directory
54-
1. Open the *App.java* file in your editor
55+
1. Navigate to the `/src/main/java/com/communication/quickstart` directory
56+
1. Open the `App.java` file in your editor
5557
1. Replace the `System.out.println("Hello world!");` statement
5658
1. Add `import` directives
5759

@@ -81,12 +83,12 @@ public class App
8183

8284
## Authenticate the client
8385

84-
Instantiate a `CommunicationIdentityClient` with your resource's access key and endpoint. Learn how to [manage your resource's connection string](../create-communication-resource.md#store-your-connection-string). In addition, you can initialize the client with any custom HTTP client the implements the `com.azure.core.http.HttpClient` interface.
86+
Instantiate a `CommunicationIdentityClient` with your resource's access key and endpoint. Learn how to [manage your resource's connection string](../../create-communication-resource.md#store-your-connection-string). In addition, you can initialize the client with any custom HTTP client that implements the `com.azure.core.http.HttpClient` interface.
8587

86-
Add the following code to the `main` method:
88+
Add the following code to the `main` method inside `App.java`:
8789

8890
```java
89-
// Your can find your endpoint and access key from your resource in the Azure portal
91+
// You can find your endpoint and access key from your resource in the Azure portal
9092
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";
9193
String accessKey = "SECRET";
9294

@@ -96,17 +98,17 @@ CommunicationIdentityClient communicationIdentityClient = new CommunicationIdent
9698
.buildClient();
9799
```
98100

99-
You can also provide the entire connection string using the `connectionString()` function instead of providing the endpoint and access key.
101+
You can also provide the entire connection string using the `connectionString()` method instead of providing the endpoint and access key.
100102
```java
101-
// Your can find your connection string from your resource in the Azure portal
103+
// Your can find your connection string from your ACS resource in the Azure portal
102104
String connectionString = "<connection_string>";
103105

104106
CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClientBuilder()
105107
.connectionString(connectionString)
106108
.buildClient();
107109
```
108110

109-
If you have an Azure Active Directory(AD) application set up, see [Use service principals](../identity/service-principal.md), you may also authenticate with AD.
111+
If you have an Azure Active Directory(Azure AD) application set up, see [Use service principals](../../identity/service-principal.md), you may also authenticate with Azure AD.
110112
```java
111113
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";
112114
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
@@ -119,16 +121,17 @@ CommunicationIdentityClient communicationIdentityClient = new CommunicationIdent
119121

120122
## Create an identity
121123

122-
Azure Communication Services maintains a lightweight identity directory. Use the `createUser` method to create a new entry in the directory with a unique `Id`. Store received identity with mapping to your application's users. For example, by storing them in your application server's database. The identity is required later to issue access tokens.
123-
124+
To create access tokens, you'll need an identity. Azure Communication Services maintains a lightweight identity directory. Use the `createUser` method to create a new entry in the directory with a unique `Id`.
124125
```java
125126
CommunicationUserIdentifier user = communicationIdentityClient.createUser();
126127
System.out.println("\nCreated an identity with ID: " + user.getId());
127128
```
128129

130+
The created identity is required later to issue access tokens. You should therefore store any received identities with a mapping to your application's user. For example, by storing them in your application server's database.
131+
129132
## Issue access tokens
130133

131-
Use the `getToken` method to issue an access token for already existing Communication Services identity. Parameter `scopes` defines set of primitives, that will authorize this access token. See the [list of supported actions](../../concepts/authentication.md). New instance of parameter `user` can be constructed based on string representation of Azure Communication Service identity.
134+
Use the `getToken` method to issue an access token for already existing Communication Services identity. The `scopes` parameter defines set of permissions and abilities that this token will be able to perform. See the [list of supported actions](../../../concepts/authentication.md) for valid values. In this case we'll use our user variable created in the previous step to get a token.
132135

133136
```java
134137
// Issue an access token with the "voip" scope for a user identity
@@ -139,9 +142,9 @@ String token = accessToken.getToken();
139142
System.out.println("\nIssued an access token with 'voip' scope that expires at: " + expiresAt + ": " + token);
140143
```
141144

142-
## Create an identity and issue token in one call
145+
## Create an identity and issue token in one request
143146

144-
Alternatively, use the 'createUserAndToken' method to to create a new entry in the directory with a unique `Id` and
147+
Alternatively, we can use the 'createUserAndToken' method to to create a new entry in the directory with a unique `Id` and
145148
issue an access token.
146149

147150
```java
@@ -162,14 +165,14 @@ Access tokens are short-lived credentials that need to be reissued. Not doing so
162165
To refresh an access token, use the `CommunicationUserIdentifier` object to reissue:
163166

164167
```java
165-
// Value existingIdentity represents identity of Azure Communication Services stored during identity creation
168+
// existingIdentity represents identity of Azure Communication Services stored during identity creation
166169
CommunicationUserIdentifier identity = new CommunicationUserIdentifier(existingIdentity.getId());
167170
AccessToken response = communicationIdentityClient.getToken(identity, scopes);
168171
```
169172

170-
## Revoke access tokens
173+
## Revoke an access token
171174

172-
In some cases, you may explicitly revoke access tokens. For example, when an application's user changes the password they use to authenticate to your service. Method `revokeTokens` invalidates all active access tokens, that were issued to the identity.
175+
In some cases, you may explicitly revoke access tokens. For example, when an application's user changes the password they use to authenticate to your service. The `revokeTokens` method invalidates all active access tokens for a particular user. In this case we'll again use the previously created user.
173176

174177
```java
175178
communicationIdentityClient.revokeTokens(user);
@@ -187,7 +190,7 @@ System.out.println("\nDeleted the user identity with ID: " + user.getId());
187190

188191
## Run the code
189192

190-
Navigate to the directory containing the *pom.xml* file and compile the project by using the following `mvn` command.
193+
Navigate to the directory containing the `pom.xml` file and compile the project by using the following `mvn` command.
191194

192195
```console
193196
mvn compile

0 commit comments

Comments
 (0)