Skip to content

Commit cff9c07

Browse files
authored
Merge pull request #175406 from stefang931/gistefan/azure-doc-pr-teams-tokens
Add CTE documentation for public preview
2 parents 9c30c17 + cc183dc commit cff9c07

17 files changed

+610
-195
lines changed

articles/communication-services/concepts/media/teams-identities/teams-identity-calling-overview.svg

Lines changed: 1 addition & 0 deletions
Loading

articles/communication-services/concepts/teams-endpoint.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ You can use the Azure Communication Services Identity SDK to exchange Azure Acti
2525

2626
Voice, video, and screen-sharing capabilities are provided via Azure Communication Services Calling SDKs. The following diagram shows an overview of the process you'll follow as you integrate your calling experiences with custom Teams endpoints.
2727

28-
![Diagram of the process of enabling the calling feature for a custom Teams endpoint experience.](./media/teams-identities/teams-identity-calling-overview.png)
28+
![Diagram of the process of enabling the calling feature for a custom Teams endpoint experience.](./media/teams-identities/teams-identity-calling-overview.svg)
2929

3030
## Chat
3131

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
---
2-
title: Quickstart - Quickly create Azure Communication Services identities for testing
3-
titleSuffix: An Azure Communication Services quickstart
4-
description: Learn how to use the Identities & Access Tokens tool in the Azure portal to use with samples and for troubleshooting.
5-
author: manoskow
6-
manager: chpalm
7-
services: azure-communication-services
8-
9-
ms.author: manoskow
10-
ms.date: 07/19/2021
11-
ms.topic: quickstart
12-
ms.service: azure-communication-services
13-
ms.subservice: identity
14-
---
15-
16-
# Quickstart: Quickly create Azure Communication Services access tokens for testing
17-
18-
In the [Azure portal](https://portal.azure.com) Communication Services extension, you can generate a Communication Services identity and access token. This lets you skip creating an authentication service, which makes it easier for you to test the sample apps and simple development scenarios. This feature is intended for small-scale validation and testing and should not be used for production scenarios. For production code, refer to the [creating access tokens quickstart](../access-tokens.md).
19-
20-
The tool showcases the behavior of the ```Identity SDK``` in a simple user experience. Tokens and identities that are created through this tool follow the same behaviors and rules as if they were created using the ```Identity SDK```. For example, access tokens expire after 24 hours.
21-
22-
## Prerequisites
23-
24-
- An [Azure Communication Services resource](../create-communication-resource.md)
25-
26-
## Create the access tokens
27-
28-
In the [Azure portal](https://portal.azure.com), navigate to the **Identities & User Access Tokens** blade within your Communication Services resource.
29-
30-
Choose the scope of the access tokens. You can select none, one, or multiple. Click **Generate**.
31-
32-
![Select the scopes of the identity and access tokens.](../media/quick-create-identity-choose-scopes.png)
33-
34-
You'll see an identity and corresponding user access token generated. You can copy these strings and use them in the [sample apps](../../samples/overview.md) and other testing scenarios.
35-
36-
![The identity and access tokens are generated and show the expiration date.](../media/quick-create-identity-generated.png)
37-
38-
## Next steps
39-
40-
41-
You may also want to:
42-
43-
- [Learn about authentication](../../concepts/authentication.md)
44-
- [Learn about client and server architecture](../../concepts/client-and-server-architecture.md)
1+
---
2+
title: Quickstart - Quickly create Azure Communication Services identities for testing
3+
titleSuffix: An Azure Communication Services quickstart
4+
description: Learn how to use the Identities & Access Tokens tool in the Azure portal to use with samples and for troubleshooting.
5+
author: manoskow
6+
manager: chpalm
7+
services: azure-communication-services
8+
9+
ms.author: manoskow
10+
ms.date: 07/19/2021
11+
ms.topic: quickstart
12+
ms.service: azure-communication-services
13+
ms.subservice: identity
14+
---
15+
16+
# Quickstart: Quickly create Azure Communication Services access tokens for testing
17+
18+
In the [Azure portal](https://portal.azure.com) Communication Services extension, you can generate a Communication Services identity and access token. This lets you skip creating an authentication service, which makes it easier for you to test the sample apps and simple development scenarios. This feature is intended for small-scale validation and testing and should not be used for production scenarios. For production code, refer to the [creating access tokens quickstart](../access-tokens.md).
19+
20+
The tool showcases the behavior of the ```Identity SDK``` in a simple user experience. Tokens and identities that are created through this tool follow the same behaviors and rules as if they were created using the ```Identity SDK```. For example, access tokens expire after 24 hours.
21+
22+
## Prerequisites
23+
24+
- An [Azure Communication Services resource](../create-communication-resource.md)
25+
26+
## Create the access tokens
27+
28+
In the [Azure portal](https://portal.azure.com), navigate to the **Identities & User Access Tokens** blade within your Communication Services resource.
29+
30+
Choose the scope of the access tokens. You can select none, one, or multiple. Click **Generate**.
31+
32+
![Select the scopes of the identity and access tokens.](../media/quick-create-identity-choose-scopes.png)
33+
34+
You'll see an identity and corresponding user access token generated. You can copy these strings and use them in the [sample apps](../../samples/overview.md) and other testing scenarios.
35+
36+
![The identity and access tokens are generated and show the expiration date.](../media/quick-create-identity-generated.png)
37+
38+
## Next steps
39+
40+
41+
You may also want to:
42+
43+
- [Learn about authentication](../../concepts/authentication.md)
44+
- [Learn about client and server architecture](../../concepts/client-and-server-architecture.md)
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
title: include file
3+
description: include file
4+
services: azure-communication-services
5+
author: gistefan
6+
manager: soricos
7+
ms.service: azure-communication-services
8+
ms.subservice: azure-communication-services
9+
ms.date: 10/08/2021
10+
ms.topic: include
11+
ms.custom: include file
12+
ms.author: gistefan
13+
---
14+
15+
## Set up prerequisites
16+
17+
- [Java Development Kit (JDK)](/azure/developer/java/fundamentals/java-jdk-install) version 8 or above.
18+
- [Apache Maven](https://maven.apache.org/download.cgi).
19+
20+
## Set up
21+
22+
### Create a new Java application
23+
24+
Open your terminal or command window. Navigate to the directory where you'd like to create your Java application. Run the command below to generate the Java project from the `maven-archetype-quickstart` template.
25+
26+
```console
27+
mvn archetype:generate -DgroupId=com.communication.quickstart -DartifactId=communication-quickstart -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
28+
```
29+
30+
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.
31+
32+
### Install the package
33+
34+
Open the `pom.xml` file in your text editor. Add the following dependency elements to the group of dependencies.
35+
36+
```xml
37+
<dependencies>
38+
<dependency>
39+
<groupId>com.azure</groupId>
40+
<artifactId>azure-communication-identity</artifactId>
41+
<version>1.2.0-beta.1</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.microsoft.azure</groupId>
45+
<artifactId>msal4j</artifactId>
46+
<version>1.11.0</version>
47+
</dependency>
48+
</dependencies>
49+
```
50+
51+
### Set up the app framework
52+
53+
From the project directory:
54+
55+
1. Navigate to the `/src/main/java/com/communication/quickstart` directory
56+
1. Open the `App.java` file in your editor
57+
1. Replace the `System.out.println("Hello world!");` statement
58+
1. Add `import` directives
59+
60+
Use the following code to begin:
61+
62+
```java
63+
package com.communication.quickstart;
64+
65+
import com.azure.communication.common.*;
66+
import com.azure.communication.identity.*;
67+
import com.azure.communication.identity.models.*;
68+
import com.azure.core.credential.*;
69+
import com.microsoft.aad.msal4j.IAuthenticationResult;
70+
import com.microsoft.aad.msal4j.InteractiveRequestParameters;
71+
import com.microsoft.aad.msal4j.PublicClientApplication;
72+
73+
import java.io.IOException;
74+
import java.time.*;
75+
import java.util.*;
76+
77+
public class App
78+
{
79+
public static void main( String[] args ) throws Exception
80+
{
81+
System.out.println("Azure Communication Services - Communication access token Quickstart");
82+
// Quickstart code goes here
83+
}
84+
}
85+
```
86+
87+
### Step 1: Receive the Azure Active Directory user token via the MSAL library
88+
89+
The first step in the token exchange flow is getting a token for your Teams user by using [Microsoft.Identity.Client](../../../active-directory/develop/reference-v2-libraries.md).
90+
91+
```java
92+
String appId = "<contoso_application_id>";
93+
String authority = "https://login.microsoftonline.com/<contoso_tenant_id>";
94+
95+
PublicClientApplication pca = PublicClientApplication.builder(appId)
96+
.authority(authority)
97+
.build();
98+
99+
String redirectUri = "http://localhost";
100+
Set<String> scope = new HashSet<String>();
101+
scope.add("https://auth.msft.communication.azure.com/VoIP");
102+
103+
InteractiveRequestParameters parameters = InteractiveRequestParameters
104+
.builder(new URI(redirectUri))
105+
.scopes(scope)
106+
.build();
107+
108+
IAuthenticationResult result = pca.acquireToken(parameters).get();
109+
```
110+
111+
### Step 2: Initialize the CommunicationIdentityClient
112+
113+
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.
114+
115+
Add the following code to the `main` method:
116+
117+
```java
118+
//You can find your connection string from your resource in the Azure portal
119+
String connectionString = "<connection_string>";
120+
121+
CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClientBuilder()
122+
.connectionString(connectionString)
123+
.buildClient();
124+
```
125+
126+
### Step 3: Exchange the Azure AD user token for the Teams access token
127+
128+
Use the `getTokenForTeamsUser` method to issue an access token for the Teams user that can be used with the Azure Communication Services SDKs.
129+
130+
```java
131+
var accessToken = communicationIdentityClient.getTokenForTeamsUser(result.accessToken());
132+
System.out.println("Token: " + accessToken.getToken());
133+
```
134+
135+
## Run the code
136+
137+
Navigate to the directory containing the `pom.xml` file and compile the project by using the following `mvn` command.
138+
139+
Then, build the package.
140+
141+
```console
142+
mvn package
143+
```
144+
145+
Run the following `mvn` command to execute the app.
146+
147+
```console
148+
mvn exec:java -Dexec.mainClass="com.communication.quickstart.App" -Dexec.cleanupDaemonThreads=false
149+
```

0 commit comments

Comments
 (0)