@azure/communication-identity 1.3.2-alpha.20250122.7 → 1.3.2-alpha.20250127.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +126 -27
- package/package.json +9 -9
package/README.md
CHANGED
@@ -35,50 +35,58 @@ You can get a key and/or connection string from your Communication Services reso
|
|
35
35
|
|
36
36
|
### Create `KeyCredential` with `AzureKeyCredential` before initializing the client
|
37
37
|
|
38
|
-
```
|
38
|
+
```ts snippet:ReadmeSampleCreateClient_KeyCredential
|
39
39
|
import { AzureKeyCredential } from "@azure/core-auth";
|
40
40
|
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
41
41
|
|
42
|
-
const
|
43
|
-
const
|
42
|
+
const key = "<some-key>";
|
43
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
44
|
+
|
45
|
+
const credential = new AzureKeyCredential(key);
|
46
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
44
47
|
```
|
45
48
|
|
46
49
|
### Using a connection string
|
47
50
|
|
48
|
-
```
|
51
|
+
```ts snippet:ReadmeSampleCreateClient_ConnectionString
|
49
52
|
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
50
53
|
|
51
|
-
|
54
|
+
// Example connection string
|
55
|
+
const connectionString =
|
56
|
+
"endpoint=https://contoso.eastus.communications.azure.net/;accesskey=secret";
|
57
|
+
|
52
58
|
const client = new CommunicationIdentityClient(connectionString);
|
53
59
|
```
|
54
60
|
|
55
61
|
### Using a `TokenCredential`
|
56
62
|
|
57
|
-
```
|
63
|
+
```ts snippet:ReadmeSampleCreateClient_TokenCredential
|
58
64
|
import { DefaultAzureCredential } from "@azure/identity";
|
59
65
|
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
60
66
|
|
67
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
68
|
+
|
61
69
|
const credential = new DefaultAzureCredential();
|
62
|
-
const client = new CommunicationIdentityClient(
|
70
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
63
71
|
```
|
64
72
|
|
65
73
|
If you use a key to initialize the client you will also need to provide the appropriate endpoint. You can get this endpoint from your Communication Services resource in [Azure Portal][azure_portal].
|
66
74
|
|
67
75
|
## Usage
|
68
76
|
|
69
|
-
### Creating
|
77
|
+
### Creating a new user
|
70
78
|
|
71
|
-
|
72
|
-
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
79
|
+
Use the `createUser` method to create a new user.
|
73
80
|
|
74
|
-
|
75
|
-
|
81
|
+
```ts snippet:ReadmeSampleCreateUser
|
82
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
83
|
+
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
76
84
|
|
77
|
-
|
85
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
78
86
|
|
79
|
-
|
87
|
+
const credential = new DefaultAzureCredential();
|
88
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
80
89
|
|
81
|
-
```typescript
|
82
90
|
const user = await client.createUser();
|
83
91
|
```
|
84
92
|
|
@@ -92,22 +100,55 @@ Use the `getToken` method to issue or refresh a token for an existing user. The
|
|
92
100
|
- `chat.join.limited` (A more limited version of chat.join that doesn't allow to add or remove participants)
|
93
101
|
- `voip.join` (Access to Calling APIs but without the authorization to start new calls)
|
94
102
|
|
95
|
-
```
|
103
|
+
```ts snippet:ReadmeSampleCreateToken
|
104
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
105
|
+
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
106
|
+
|
107
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
108
|
+
|
109
|
+
const credential = new DefaultAzureCredential();
|
110
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
111
|
+
|
112
|
+
const user = await client.createUser();
|
113
|
+
|
96
114
|
const { token } = await client.getToken(user, ["chat"]);
|
97
115
|
```
|
98
116
|
|
99
117
|
To refresh the user token, issue another token with the same user.
|
100
118
|
|
101
|
-
```
|
102
|
-
|
119
|
+
```ts snippet:ReadmeSampleRefreshToken
|
120
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
121
|
+
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
122
|
+
|
123
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
124
|
+
|
125
|
+
const credential = new DefaultAzureCredential();
|
126
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
127
|
+
|
128
|
+
const user = await client.createUser();
|
129
|
+
|
130
|
+
let { token } = await client.getToken(user, ["chat"]);
|
131
|
+
|
132
|
+
// Refresh the token again
|
133
|
+
({ token } = await client.getToken(user, ["chat"]));
|
103
134
|
```
|
104
135
|
|
105
136
|
### Creating a user token with custom expiration
|
106
137
|
|
107
138
|
It's also possible to create a Communication Identity access token by customizing the expiration time. Validity period of the token must be within [60,1440] minutes range. If not provided, the default value of 1440 minutes (24 hours) will be used.
|
108
139
|
|
109
|
-
```
|
110
|
-
|
140
|
+
```ts snippet:ReadmeSampleCreateTokenWithOptions
|
141
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
142
|
+
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
143
|
+
|
144
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
145
|
+
|
146
|
+
const credential = new DefaultAzureCredential();
|
147
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
148
|
+
|
149
|
+
const user = await client.createUser();
|
150
|
+
|
151
|
+
const tokenOptions = { tokenExpiresInMinutes: 60 };
|
111
152
|
const { token } = await client.getToken(user, ["chat"], tokenOptions);
|
112
153
|
```
|
113
154
|
|
@@ -115,7 +156,15 @@ const { token } = await client.getToken(user, ["chat"], tokenOptions);
|
|
115
156
|
|
116
157
|
For convenience, use `createUserAndToken` to create a new user and issue a token with one function call. This translates into a single web request as opposed to creating a user first and then issuing a token.
|
117
158
|
|
118
|
-
```
|
159
|
+
```ts snippet:ReadmeSampleCreateUserAndToken
|
160
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
161
|
+
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
162
|
+
|
163
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
164
|
+
|
165
|
+
const credential = new DefaultAzureCredential();
|
166
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
167
|
+
|
119
168
|
const { user, token } = await client.createUserAndToken(["chat"]);
|
120
169
|
```
|
121
170
|
|
@@ -123,8 +172,16 @@ const { user, token } = await client.createUserAndToken(["chat"]);
|
|
123
172
|
|
124
173
|
It's also possible to create a Communication Identity access token by customizing the expiration time. Validity period of the token must be within [60,1440] minutes range. If not provided, the default value of 1440 minutes (24 hours) will be used.
|
125
174
|
|
126
|
-
```
|
127
|
-
|
175
|
+
```ts snippet:ReadmeSampleCreateUserAndTokenWithOptions
|
176
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
177
|
+
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
178
|
+
|
179
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
180
|
+
|
181
|
+
const credential = new DefaultAzureCredential();
|
182
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
183
|
+
|
184
|
+
const userAndTokenOptions = { tokenExpiresInMinutes: 60 };
|
128
185
|
const { user, token } = await client.createUserAndToken(["chat"], userAndTokenOptions);
|
129
186
|
```
|
130
187
|
|
@@ -132,7 +189,19 @@ const { user, token } = await client.createUserAndToken(["chat"], userAndTokenOp
|
|
132
189
|
|
133
190
|
Use the `revokeTokens` method to revoke all issued tokens for a user.
|
134
191
|
|
135
|
-
```
|
192
|
+
```ts snippet:ReadmeSampleRevokeTokens
|
193
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
194
|
+
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
195
|
+
|
196
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
197
|
+
|
198
|
+
const credential = new DefaultAzureCredential();
|
199
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
200
|
+
|
201
|
+
// Create user
|
202
|
+
const user = await client.createUser();
|
203
|
+
|
204
|
+
// Later when you want to revoke the user's tokens
|
136
205
|
await client.revokeTokens(user);
|
137
206
|
```
|
138
207
|
|
@@ -140,7 +209,19 @@ await client.revokeTokens(user);
|
|
140
209
|
|
141
210
|
Use the `deleteUser` method to delete a user.
|
142
211
|
|
143
|
-
```
|
212
|
+
```ts snippet:ReadmeSampleDeleteUser
|
213
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
214
|
+
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
215
|
+
|
216
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
217
|
+
|
218
|
+
const credential = new DefaultAzureCredential();
|
219
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
220
|
+
|
221
|
+
// Create user
|
222
|
+
const user = await client.createUser();
|
223
|
+
|
224
|
+
// Later when you want to delete the user
|
144
225
|
await client.deleteUser(user);
|
145
226
|
```
|
146
227
|
|
@@ -148,8 +229,16 @@ await client.deleteUser(user);
|
|
148
229
|
|
149
230
|
Use `getTokenForTeamsUser` method to exchange an Azure AD access token of a Teams user for a new `CommunicationAccessToken` with a matching expiration time.
|
150
231
|
|
151
|
-
```
|
152
|
-
|
232
|
+
```ts snippet:ReadmeSampleGetTokenForTeamsUser
|
233
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
234
|
+
import { CommunicationIdentityClient } from "@azure/communication-identity";
|
235
|
+
|
236
|
+
const endpoint = "https://contoso.eastus.communications.azure.net";
|
237
|
+
|
238
|
+
const credential = new DefaultAzureCredential();
|
239
|
+
const client = new CommunicationIdentityClient(endpoint, credential);
|
240
|
+
|
241
|
+
const { token, expiresOn } = await client.getTokenForTeamsUser({
|
153
242
|
teamsUserAadToken: "<aad-access-token-of-a-teams-user>",
|
154
243
|
clientId: "<cliend-id-of-an-aad-application>",
|
155
244
|
userObjectId: "<aad-object-id-of-a-teams-user>",
|
@@ -158,6 +247,16 @@ await client.getTokenForTeamsUser({
|
|
158
247
|
|
159
248
|
## Troubleshooting
|
160
249
|
|
250
|
+
### Logging
|
251
|
+
|
252
|
+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
253
|
+
|
254
|
+
```ts snippet:SetLogLevel
|
255
|
+
import { setLogLevel } from "@azure/logger";
|
256
|
+
|
257
|
+
setLogLevel("info");
|
258
|
+
```
|
259
|
+
|
161
260
|
## Next steps
|
162
261
|
|
163
262
|
Please take a look at the
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@azure/communication-identity",
|
3
|
-
"version": "1.3.2-alpha.
|
3
|
+
"version": "1.3.2-alpha.20250127.1",
|
4
4
|
"description": "SDK for Azure Communication service which facilitates user token administration.",
|
5
5
|
"sdk-type": "client",
|
6
6
|
"main": "./dist/commonjs/index.js",
|
@@ -33,7 +33,7 @@
|
|
33
33
|
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
|
34
34
|
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
|
35
35
|
"unit-test:node": "dev-tool run test:vitest",
|
36
|
-
"update-snippets": "
|
36
|
+
"update-snippets": "dev-tool run update-snippets"
|
37
37
|
},
|
38
38
|
"//metadata": {
|
39
39
|
"constantPaths": [
|
@@ -95,13 +95,13 @@
|
|
95
95
|
"@azure/communication-common": "^2.3.1",
|
96
96
|
"@azure/core-auth": "^1.9.0",
|
97
97
|
"@azure/core-client": "^1.9.2",
|
98
|
-
"@azure/core-lro": "^2.2
|
98
|
+
"@azure/core-lro": "^2.7.2",
|
99
99
|
"@azure/core-paging": "^1.6.2",
|
100
|
-
"@azure/core-rest-pipeline": "^1.18.
|
100
|
+
"@azure/core-rest-pipeline": "^1.18.2",
|
101
101
|
"@azure/core-tracing": "^1.2.0",
|
102
102
|
"@azure/logger": "^1.1.4",
|
103
|
-
"events": "^3.
|
104
|
-
"tslib": "^2.
|
103
|
+
"events": "^3.3.0",
|
104
|
+
"tslib": "^2.8.1"
|
105
105
|
},
|
106
106
|
"devDependencies": {
|
107
107
|
"@azure-tools/test-credential": "^2.0.0",
|
@@ -113,13 +113,13 @@
|
|
113
113
|
"@azure/identity": "^4.5.0",
|
114
114
|
"@azure/msal-node": "^2.16.1",
|
115
115
|
"@types/node": "^18.0.0",
|
116
|
-
"@vitest/browser": "^
|
117
|
-
"@vitest/coverage-istanbul": "^
|
116
|
+
"@vitest/browser": "^3.0.3",
|
117
|
+
"@vitest/coverage-istanbul": "^3.0.3",
|
118
118
|
"dotenv": "^16.0.0",
|
119
119
|
"eslint": "^9.9.0",
|
120
120
|
"playwright": "^1.48.2",
|
121
121
|
"typescript": "~5.7.2",
|
122
|
-
"vitest": "^
|
122
|
+
"vitest": "^3.0.3"
|
123
123
|
},
|
124
124
|
"type": "module",
|
125
125
|
"tshy": {
|