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
1. Create a `src/App.jsx` file with the following content and import the `AzureCommunicationTokenCredential` and `InteractiveBrowserCredential` classes from the Azure Communication Common and Azure Identity SDKs, respectively. Also make sure to update the `clientId`, `tenantId`, and `resourceEndpoint` variables with your Microsoft Entra client ID, tenant ID, and Azure Communication Services resource endpoint URI:
68
95
69
-
// Quickstart code goes here
96
+
```javascript
97
+
import React, { useState } from "react";
98
+
import { AzureCommunicationTokenCredential } from "@azure/communication-common";
99
+
import { InteractiveBrowserCredential } from "@azure/identity";
100
+
101
+
function App() {
102
+
// Set your Microsoft Entra client ID and tenant ID, Azure Communication Services resource endpoint URI.
You can import any implementation of the [TokenCredential](https://learn.microsoft.com/javascript/api/%40azure/core-auth/tokencredential) interface from the [Azure Identity SDK for JavaScript](https://www.npmjs.com/package/@azure/identity) to authenticate with Microsoft Entra ID. In this quickstart, we use the `InteractiveBrowserCredential` class, which is suitable for browser basic authentication scenarios. For a full list of the credentials offered, see [Credential Classes](https://learn.microsoft.com/javascript/api/overview/azure/identity-readme#credential-classes).
75
138
76
-
1. Save the newfile as `obtain-access-token-for-entra-id-user.js`in the `entra-id-users-support-quickstart` directory.
### Step 1: Initialize implementation of TokenCredential from Azure Identity SDK
81
142
82
-
The first step in obtaining Communication Services access token for Entra ID user is getting an Entra ID access token for your Entra ID user by using [Azure Identity](https://learn.microsoft.com/javascript/api/overview/azure/identity-readme) SDK. The code below retrieves the Contoso Entra client ID and the Fabrikam tenant ID from environment variables named `ENTRA_CLIENT_ID` and `ENTRA_TENANT_ID`. To enable authentication for users across multiple tenants, initialize the `InteractiveBrowserCredential` class with the authority set to `https://login.microsoftonline.com/organizations`. For more information, see [Authority](https://learn.microsoft.com//entra/identity-platform/msal-client-application-configuration#authority).
143
+
The first step in obtaining Communication Services access token for Entra ID user is getting an Entra ID access token for your Entra ID user by using [Azure Identity](https://learn.microsoft.com/javascript/api/overview/azure/identity-readme) SDK. To enable authentication for users across multiple tenants, initialize the `InteractiveBrowserCredential` class with the authority set to `https://login.microsoftonline.com/organizations`. For more information, see [Authority](https://learn.microsoft.com//entra/identity-platform/msal-client-application-configuration#authority).
83
144
84
145
```javascript
85
-
// This code demonstrates how to fetch your Microsoft Entra client ID and tenant ID from environment variables.
86
-
const clientId = process.env['ENTRA_CLIENT_ID'];
87
-
const tenantId = process.env['ENTRA_TENANT_ID'];
88
-
89
146
// Initialize InteractiveBrowserCredential for use with AzureCommunicationTokenCredential.
90
147
const entraTokenCredential = new InteractiveBrowserCredential({
Instantiate a `AzureCommunicationTokenCredential`with the TokenCredential created above and your Communication Services resource endpoint URI.The code below retrieves the endpoint for the resource from an environment variable named `COMMUNICATION_SERVICES_RESOURCE_ENDPOINT`.
156
+
Instantiate a `AzureCommunicationTokenCredential` with the TokenCredential created above and your Communication Services resource endpoint URI.
99
157
100
158
```javascript
101
-
const app = express();
102
-
103
-
app.get('/', async (req, res) => {
104
-
try {
105
-
console.log("Azure Communication Services - Obtain Access Token for Entra ID User Quickstart");
106
-
// This code demonstrates how to fetch your Azure Communication Services resource endpoint URI
Providing scopes is optional. When not specified, the `https://communication.azure.com/clients/.default` scope is automatically used, requesting all API permissions for Communication Services Clients that have been registered on the client application.
@@ -136,13 +174,13 @@ Use the `getToken` method to obtain an access token for the Entra ID user. The `
136
174
```javascript
137
175
// To obtain a Communication Services access token for Microsoft Entra ID call getToken() function.
138
176
let accessToken =awaitentraCommunicationTokenCredential.getToken();
139
-
console.log("Token:", accessToken);
177
+
setAccessToken(accessToken.token);
140
178
```
141
179
142
180
## Run the code
143
181
144
-
From a console prompt, navigate to the directory containing the *obtain-access-token-for-entra-id-user.js* file, then execute the following `node` command to run the app.
182
+
From a console prompt, navigate to the directory *entra-id-users-support-quickstart*, then execute the following `npm` command to run the app.
0 commit comments