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
description: This is the JavaScript version of creating a Trusted Service for Communication Services.
3
+
description: This article describes the JavaScript version of creating a Trusted Service for Azure Communication Services.
4
4
author: tophpalmer
5
5
manager: nimag
6
6
services: azure-communication-services
@@ -10,42 +10,44 @@ ms.topic: include
10
10
ms.service: azure-communication-services
11
11
---
12
12
13
-
## Download Code
13
+
## Download code
14
14
15
-
Find the finalized code for this quickstart on [GitHub](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/trusted-authentication-service)
15
+
Find the finalized code for this quickstart on [GitHub](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/trusted-authentication-service).
16
16
17
17
## Prerequisites
18
18
19
-
- An Azure account with an active subscription. For details, see [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
19
+
- An Azure account with an active subscription. If you don't have an Azure subscription, you can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
20
20
-[Visual Studio Code](https://code.visualstudio.com/) on one of the [supported platforms](https://code.visualstudio.com/docs/supporting/requirements#_platforms).
21
21
-[Node.js](https://nodejs.org/), Active LTS and Maintenance LTS versions (10.14.1 recommended). Use the `node --version` command to check your version.
22
22
- The [Azure Functions extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions) for Visual Studio Code.
23
-
- An active Communication Services resource and connection string. [Create a Communication Services resource](../../quickstarts/create-communication-resource.md).
23
+
- An active Communication Services resource and connection string. For more information, see [Quickstart: Create and manage Communication Services resources](../../quickstarts/create-communication-resource.md).
24
24
25
25
## Overview
26
26
27
-
:::image type="content" source="../media/trusted-service-architecture.png" alt-text="Diagram for trusted service architecture":::
27
+
:::image type="content" source="../media/trusted-service-architecture.png" alt-text="Diagram that shows trusted service architecture.":::
28
28
29
-
For this tutorial we'll be creating an Azure Function that will serve as a trusted token provisioning service. You can use this tutorial to bootstrap your own token provisioning service.
29
+
For this tutorial, you create a function app that serves as a trusted token provisioning service. You can use this tutorial to bootstrap your own token provisioning service.
30
30
31
-
This service is responsible for authenticating users to Azure Communication Services. Users of your Communication Services applications will require an `Access Token` in order to participate in chat threads and VoIP calls. The Azure Function will work as a trusted middleman between the user and the Communication Services. This allows you to provision access tokens without exposing your resource connection string to your users.
31
+
This service is responsible for authenticating users to Communication Services. Users of your Communication Services applications require an access token to participate in chat threads and VoIP calls. The function works as a trusted middleman between the user and Communication Services. You can provision access tokens without exposing your resource connection string to your users.
32
32
33
33
For more information, see the [client-server architecture](../../concepts/identity-model.md#client-server-architecture) and [authentication and authorization](../../concepts/authentication.md) conceptual documentation.
34
34
35
-
## Setting up
35
+
## Setup
36
36
37
-
### Azure Functions set up
37
+
This section describes the procedures to set up a function.
38
38
39
-
Let's first set up the basic structure for our Azure function. Step by step instructions on the set up can be found here: [Create a function using Visual Studio Code](../../../azure-functions/create-first-function-vs-code-csharp.md?pivots=programming-language-javascript)
39
+
### Azure Functions setup
40
40
41
-
Our Azure Function requires the following configuration:
41
+
Let's first set up the basic structure for the function. For step-by-step instructions for setup, see [Quickstart: Create a C# function in Azure by using Visual Studio Code](../../../azure-functions/create-first-function-vs-code-csharp.md?pivots=programming-language-javascript).
42
42
43
-
- Language: JavaScript
44
-
- Template: HTTP Trigger
45
-
- Authorization Level: Anonymous (This can be switched later if you prefer a different authorization model)
46
-
- Function Name: User defined
43
+
The function requires the following configuration:
47
44
48
-
After following the [Azure Functions instructions](../../../azure-functions/create-first-function-vs-code-csharp.md?pivots=programming-language-javascript) with the above configuration, you should have a project in Visual Studio Code for the Azure Function with an `index.js` file that contains the function itself. The code inside of this file should be as follows:
45
+
-**Language**: JavaScript
46
+
-**Template**: HTTP Trigger
47
+
-**Authorization Level**: Anonymous (if you prefer a different authorization model, you can switch it later)
48
+
-**Function Name**: User defined
49
+
50
+
After you follow the instructions in [Quickstart: Create a C# function in Azure by using Visual Studio Code](../../../azure-functions/create-first-function-vs-code-csharp.md?pivots=programming-language-javascript) with the preceding configuration, you should have a project in Visual Studio Code for the function with an `index.js` file that contains the function itself. The following code inside of the file should be:
To allow our Azure Function to generate `User Access Tokens`, we'll first need use the connection string for our Communication Services resource.
94
+
To allow your function to generate user access tokens, you first need to use the connection string for your Communication Services resource.
93
95
94
-
Visit the [resource provisioning quickstart](../../quickstarts/create-communication-resource.md) for more information on retrieving your connection string.
96
+
For more information on how to retrieve your connection string, see [Quickstart: Create and manage Communication Services resources](../../quickstarts/create-communication-resource.md).
95
97
96
98
```javascript
97
99
constconnectionString='INSERT YOUR RESOURCE CONNECTION STRING'
98
100
```
99
101
100
-
Next, we'll modify our original function to generate `User Access Tokens`.
102
+
Next, you modify your original function to generate user access tokens.
101
103
102
-
`User Access Tokens` are generated by creating a user from the `createUser` method. Once the user is created we can use the `getToken` method to generate a token for that user which the Azure Function returns.
104
+
To generate user access tokens, use the `createUser` method to create a user. After the user is created, use the `getToken` method to generate a token for that user, which the function returns.
103
105
104
-
For this example, we will configure the token scope to `voip`. Other scopes might be necessary for your application. Learn more about [scopes](../../quickstarts/identity/access-tokens.md)
106
+
For this example, you configure the token scope to `voip`. Other scopes might be necessary for your application. To learn more about scopes, see [Create and manage access tokens](../../quickstarts/identity/access-tokens.md).
For existing Communication Services `CommunicationUser`, you can skip the creation step and just generate an access token. More details found in the [Create user access tokens quickstart](../../quickstarts/identity/access-tokens.md).
122
+
For the existing Communication Services `CommunicationUser` parameter, you can skip the creation step and generate an access token. For more information, see [Create and manage access tokens](../../quickstarts/identity/access-tokens.md).
123
+
124
+
## Test the function
121
125
122
-
## Test the Azure Function
126
+
Run the function locally by using `F5`. This action initializes the function locally and makes it accessible through `http://localhost:7071/api/FUNCTION_NAME`. For more information on running locally, see [Quickstart: Create a C# function in Azure by using Visual Studio Code](../../../azure-functions/create-first-function-vs-code-csharp.md?pivots=programming-language-javascript#run-the-function-locally).
123
127
124
-
Run the Azure Function locally using `F5`. This will initialize the Azure Function locally and make it accessible through: `http://localhost:7071/api/FUNCTION_NAME`. Check out additional documentation on [running locally](../../../azure-functions/create-first-function-vs-code-csharp.md?pivots=programming-language-javascript#run-the-function-locally)
128
+
Open the URL on your browser and you see a response body with the Communication User ID, the token, and the expiration for the token.
125
129
126
-
Open the URL on your browser and you should see a response body with the Communication User ID, token and expiration for the token.
130
+
:::image type="content" source="../media/trusted-service-sample-response.png" alt-text="Screenshot that shows a response example for the created function.":::
127
131
128
-
:::image type="content" source="../media/trusted-service-sample-response.png" alt-text="Screenshot showing a Response example for the created Azure Function.":::
132
+
## Deploy the function to Azure
129
133
130
-
## Deploy the Function to Azure
134
+
To deploy your function, follow the step-by-step instructions in [Quickstart: Create a C# function in Azure by using Visual Studio Code](../../../azure-functions/create-first-function-vs-code-csharp.md?pivots=programming-language-javascript#sign-in-to-azure).
131
135
132
-
To deploy your Azure Function, you can follow [step by step instructions](../../../azure-functions/create-first-function-vs-code-csharp.md?pivots=programming-language-javascript#sign-in-to-azure)
136
+
In summary, you need to:
133
137
134
-
In summary, you will need to:
135
-
1. Sign in to Azure from Visual Studio
136
-
2. Publish your project to your Azure account. Here you will need to choose an existing subscription.
137
-
3. Create a new Azure Function resource using the Visual Studio wizard or use an existing resource. For a new resource, you will need to configure it to your desired region, runtime and unique identifier.
138
-
4. Wait for deployment to finalize
139
-
5. Run the function 🎉
138
+
1. Sign in to Azure from Visual Studio.
139
+
1. Publish your project to your Azure account. Here you need to choose an existing subscription.
140
+
1. Create a new function resource by using the Visual Studio wizard or an existing resource. For a new resource, you need to configure it to your desired region, runtime, and unique identifier.
141
+
1. Wait for deployment to finalize.
142
+
1. Run the function.
140
143
141
-
## Run Azure Function
144
+
## Run the function
142
145
143
-
Run the Azure function using the url`http://<function-appn-ame>.azurewebsites.net/api/<function-name>`
146
+
Run the function by using the URL`http://<function-appn-ame>.azurewebsites.net/api/<function-name>`.
144
147
145
-
You can find the URL by right clicking the function on Visual Studio Code and copying the Function URL.
148
+
To find the URL, right-click the function in Visual Studio Code and copy the function URL.
146
149
147
-
For more information on [running your Azure function](../../../azure-functions/create-first-function-vs-code-csharp.md?pivots=programming-language-javascript#run-the-function-in-azure)
150
+
For more information on how to run your function, see [Quickstart: Create a C# function in Azure by using Visual Studio Code](../../../azure-functions/create-first-function-vs-code-csharp.md?pivots=programming-language-javascript#run-the-function-in-azure).
0 commit comments