You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
20
22
21
23
Any prices seen in images throughout this tutorial are for demonstration purposes only.
Copy file name to clipboardExpand all lines: articles/communication-services/quickstarts/includes/access-tokens/access-token-java.md
+27-24Lines changed: 27 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,21 +6,21 @@ author: tomaschladek
6
6
manager: nmurav
7
7
ms.service: azure-communication-services
8
8
ms.subservice: azure-communication-services
9
-
ms.date: 06/30/2021
9
+
ms.date: 11/17/2021
10
10
ms.topic: include
11
11
ms.custom: include file
12
12
ms.author: tchladek
13
13
---
14
14
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
-
18
15
## Prerequisites
19
16
20
17
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
21
18
-[Java Development Kit (JDK)](/azure/developer/java/fundamentals/java-jdk-install) version 8 or above.
- 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).
24
24
25
25
## Setting Up
26
26
@@ -32,9 +32,9 @@ Open your terminal or command window. Navigate to the directory where you'd like
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.
36
36
37
-
### Install the package
37
+
### Install the ACS packages
38
38
39
39
Open the **pom.xml** file in your text editor. Add the following dependency element to the group of dependencies.
40
40
@@ -46,12 +46,14 @@ Open the **pom.xml** file in your text editor. Add the following dependency elem
46
46
</dependency>
47
47
```
48
48
49
+
This will instruct Maven to install the ACS Identity SDK when we use it later on.
50
+
49
51
### Set up the app framework
50
52
51
53
From the project directory:
52
54
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
55
57
1. Replace the `System.out.println("Hello world!");` statement
56
58
1. Add `import` directives
57
59
@@ -81,12 +83,12 @@ public class App
81
83
82
84
## Authenticate the client
83
85
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.
85
87
86
-
Add the following code to the `main` method:
88
+
Add the following code to the `main` method inside `App.java`:
87
89
88
90
```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
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.
@@ -119,16 +121,17 @@ CommunicationIdentityClient communicationIdentityClient = new CommunicationIdent
119
121
120
122
## Create an identity
121
123
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`.
124
125
```java
125
126
CommunicationUserIdentifier user = communicationIdentityClient.createUser();
126
127
System.out.println("\nCreated an identity with ID: "+ user.getId());
127
128
```
128
129
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
+
129
132
## Issue access tokens
130
133
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.
132
135
133
136
```java
134
137
// Issue an access token with the "voip" scope for a user identity
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.
173
176
174
177
```java
175
178
communicationIdentityClient.revokeTokens(user);
@@ -187,7 +190,7 @@ System.out.println("\nDeleted the user identity with ID: " + user.getId());
187
190
188
191
## Run the code
189
192
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.
0 commit comments