@azure/communication-common 2.3.2-alpha.20250122.2 → 2.3.2-alpha.20250127.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -4
- package/package.json +11 -12
package/README.md
CHANGED
|
@@ -42,7 +42,9 @@ The tokens supplied to the `AzureCommunicationTokenCredential` either through th
|
|
|
42
42
|
|
|
43
43
|
For a short-lived clients, refreshing the token upon expiry is not necessary and the `AzureCommunicationTokenCredential` may be instantiated with a static token.
|
|
44
44
|
|
|
45
|
-
```
|
|
45
|
+
```ts snippet:ReadmeSampleCredentialStaticToken
|
|
46
|
+
import { AzureCommunicationTokenCredential } from "@azure/communication-common";
|
|
47
|
+
|
|
46
48
|
const tokenCredential = new AzureCommunicationTokenCredential(
|
|
47
49
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjM2MDB9.adM-ddBZZlQ1WlN3pdPBOF5G4Wh9iZpxNP_fSvpF4cWs",
|
|
48
50
|
);
|
|
@@ -52,7 +54,14 @@ const tokenCredential = new AzureCommunicationTokenCredential(
|
|
|
52
54
|
|
|
53
55
|
Here we assume that we have a function `fetchTokenFromMyServerForUser` that makes a network request to retrieve a JWT token string for a user. We pass it into the credential to fetch a token for Bob from our own server. Our server would use the Azure Communication Identity library to issue tokens. It's necessary that the `fetchTokenFromMyServerForUser` function returns a valid token (with an expiration date set in the future) at all times.
|
|
54
56
|
|
|
55
|
-
```
|
|
57
|
+
```ts snippet:ReadmeSampleCredentialCallback
|
|
58
|
+
import { AzureCommunicationTokenCredential } from "@azure/communication-common";
|
|
59
|
+
|
|
60
|
+
function fetchTokenFromMyServerForUser(user: string): Promise<string> {
|
|
61
|
+
// Your custom implementation to fetch a token for the user
|
|
62
|
+
return Promise.resolve("some-unique-token-for-" + user);
|
|
63
|
+
}
|
|
64
|
+
|
|
56
65
|
const tokenCredential = new AzureCommunicationTokenCredential({
|
|
57
66
|
tokenRefresher: async () => fetchTokenFromMyServerForUser("bob@contoso.com"),
|
|
58
67
|
});
|
|
@@ -62,7 +71,14 @@ const tokenCredential = new AzureCommunicationTokenCredential({
|
|
|
62
71
|
|
|
63
72
|
Setting `refreshProactively` to true will call your `tokenRefresher` function when the token is close to expiry.
|
|
64
73
|
|
|
65
|
-
```
|
|
74
|
+
```ts snippet:ReadmeSampleCredentialProactiveRefresh
|
|
75
|
+
import { AzureCommunicationTokenCredential } from "@azure/communication-common";
|
|
76
|
+
|
|
77
|
+
function fetchTokenFromMyServerForUser(user: string): Promise<string> {
|
|
78
|
+
// Your custom implementation to fetch a token for the user
|
|
79
|
+
return Promise.resolve("some-unique-token-for-" + user);
|
|
80
|
+
}
|
|
81
|
+
|
|
66
82
|
const tokenCredential = new AzureCommunicationTokenCredential({
|
|
67
83
|
tokenRefresher: async () => fetchTokenFromMyServerForUser("bob@contoso.com"),
|
|
68
84
|
refreshProactively: true,
|
|
@@ -73,7 +89,14 @@ const tokenCredential = new AzureCommunicationTokenCredential({
|
|
|
73
89
|
|
|
74
90
|
Passing `initialToken` is an optional optimization to skip the first call to `tokenRefresher`. You can use this to separate the boot from your application from subsequent token refresh cycles.
|
|
75
91
|
|
|
76
|
-
```
|
|
92
|
+
```ts snippet:ReadmeSampleCredentialProactiveRefreshWithInitialToken
|
|
93
|
+
import { AzureCommunicationTokenCredential } from "@azure/communication-common";
|
|
94
|
+
|
|
95
|
+
function fetchTokenFromMyServerForUser(user: string): Promise<string> {
|
|
96
|
+
// Your custom implementation to fetch a token for the user
|
|
97
|
+
return Promise.resolve("some-unique-token-for-" + user);
|
|
98
|
+
}
|
|
99
|
+
|
|
77
100
|
const tokenCredential = new AzureCommunicationTokenCredential({
|
|
78
101
|
tokenRefresher: async () => fetchTokenFromMyServerForUser("bob@contoso.com"),
|
|
79
102
|
refreshProactively: true,
|
|
@@ -86,6 +109,16 @@ const tokenCredential = new AzureCommunicationTokenCredential({
|
|
|
86
109
|
|
|
87
110
|
- **Invalid token specified**: Make sure the token you are passing to the `AzureCommunicationTokenCredential` constructor or to the `tokenRefresher` callback is a bare JWT token string. E.g. if you're using the [Azure Communication Identity library][invalid_token_sdk] or [REST API][invalid_token_rest] to obtain the token, make sure you're passing just the `token` part of the response object.
|
|
88
111
|
|
|
112
|
+
### Logging
|
|
113
|
+
|
|
114
|
+
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`:
|
|
115
|
+
|
|
116
|
+
```ts snippet:SetLogLevel
|
|
117
|
+
import { setLogLevel } from "@azure/logger";
|
|
118
|
+
|
|
119
|
+
setLogLevel("info");
|
|
120
|
+
```
|
|
121
|
+
|
|
89
122
|
## Next steps
|
|
90
123
|
|
|
91
124
|
- [Read more about Communication user access tokens](https://learn.microsoft.com/azure/communication-services/concepts/authentication?tabs=javascript)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/communication-common",
|
|
3
|
-
"version": "2.3.2-alpha.
|
|
3
|
+
"version": "2.3.2-alpha.20250127.1",
|
|
4
4
|
"description": "Common package for Azure Communication services.",
|
|
5
5
|
"sdk-type": "client",
|
|
6
6
|
"main": "./dist/commonjs/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
|
|
31
31
|
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --no-test-proxy --browser",
|
|
32
32
|
"unit-test:node": "dev-tool run test:vitest --no-test-proxy",
|
|
33
|
-
"update-snippets": "
|
|
33
|
+
"update-snippets": "dev-tool run update-snippets"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"dist/",
|
|
@@ -58,28 +58,27 @@
|
|
|
58
58
|
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@azure/abort-controller": "^2.1.2",
|
|
61
|
-
"@azure/core-auth": "^1.
|
|
62
|
-
"@azure/core-rest-pipeline": "^1.
|
|
61
|
+
"@azure/core-auth": "^1.9.0",
|
|
62
|
+
"@azure/core-rest-pipeline": "^1.18.2",
|
|
63
63
|
"@azure/core-tracing": "^1.2.0",
|
|
64
|
-
"@azure/core-util": "^1.
|
|
65
|
-
"events": "^3.
|
|
64
|
+
"@azure/core-util": "^1.11.0",
|
|
65
|
+
"events": "^3.3.0",
|
|
66
66
|
"jwt-decode": "^4.0.0",
|
|
67
|
-
"tslib": "^2.
|
|
67
|
+
"tslib": "^2.8.1"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@azure-tools/test-utils-vitest": ">=1.0.0-alpha <1.0.0-alphb",
|
|
71
71
|
"@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
|
|
72
72
|
"@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
|
|
73
|
+
"@azure/logger": "^1.1.4",
|
|
73
74
|
"@types/node": "^18.0.0",
|
|
74
|
-
"@vitest/browser": "^
|
|
75
|
-
"@vitest/coverage-istanbul": "^
|
|
75
|
+
"@vitest/browser": "^3.0.3",
|
|
76
|
+
"@vitest/coverage-istanbul": "^3.0.3",
|
|
76
77
|
"eslint": "^9.9.0",
|
|
77
|
-
"inherits": "^2.0.3",
|
|
78
78
|
"mockdate": "^3.0.5",
|
|
79
79
|
"playwright": "^1.48.0",
|
|
80
80
|
"typescript": "~5.7.2",
|
|
81
|
-
"
|
|
82
|
-
"vitest": "^2.1.3"
|
|
81
|
+
"vitest": "^3.0.3"
|
|
83
82
|
},
|
|
84
83
|
"type": "module",
|
|
85
84
|
"tshy": {
|