@azure/communication-common 2.4.2-alpha.20260211.1 → 2.5.0
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 +47 -1
- package/dist/browser/autoRefreshTokenCredential.d.ts +20 -4
- package/dist/browser/autoRefreshTokenCredential.d.ts.map +1 -1
- package/dist/browser/autoRefreshTokenCredential.js +13 -4
- package/dist/browser/autoRefreshTokenCredential.js.map +1 -1
- package/dist/browser/azureCommunicationTokenCredential.d.ts +3 -2
- package/dist/browser/azureCommunicationTokenCredential.d.ts.map +1 -1
- package/dist/browser/azureCommunicationTokenCredential.js +3 -2
- package/dist/browser/azureCommunicationTokenCredential.js.map +1 -1
- package/dist/browser/credential/communicationAccessKeyCredentialPolicy.d.ts.map +1 -1
- package/dist/browser/credential/communicationAccessKeyCredentialPolicy.js +6 -10
- package/dist/browser/credential/communicationAccessKeyCredentialPolicy.js.map +1 -1
- package/dist/browser/entraTokenCredential.d.ts.map +1 -1
- package/dist/browser/entraTokenCredential.js +12 -7
- package/dist/browser/entraTokenCredential.js.map +1 -1
- package/dist/browser/index.d.ts +4 -3
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +1 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/logger.d.ts +3 -0
- package/dist/browser/logger.d.ts.map +1 -0
- package/dist/browser/logger.js +6 -0
- package/dist/browser/logger.js.map +1 -0
- package/dist/browser/tokenParser.d.ts +9 -1
- package/dist/browser/tokenParser.d.ts.map +1 -1
- package/dist/browser/tokenParser.js +64 -3
- package/dist/browser/tokenParser.js.map +1 -1
- package/dist/commonjs/autoRefreshTokenCredential.d.ts +20 -4
- package/dist/commonjs/autoRefreshTokenCredential.d.ts.map +1 -1
- package/dist/commonjs/autoRefreshTokenCredential.js +118 -95
- package/dist/commonjs/autoRefreshTokenCredential.js.map +7 -1
- package/dist/commonjs/azureCommunicationTokenCredential.d.ts +3 -2
- package/dist/commonjs/azureCommunicationTokenCredential.d.ts.map +1 -1
- package/dist/commonjs/azureCommunicationTokenCredential.js +64 -47
- package/dist/commonjs/azureCommunicationTokenCredential.js.map +7 -1
- package/dist/commonjs/communicationTokenCredential.js +16 -5
- package/dist/commonjs/communicationTokenCredential.js.map +7 -1
- package/dist/commonjs/credential/clientArguments.js +46 -40
- package/dist/commonjs/credential/clientArguments.js.map +7 -1
- package/dist/commonjs/credential/communicationAccessKeyCredentialPolicy.d.ts.map +1 -1
- package/dist/commonjs/credential/communicationAccessKeyCredentialPolicy.js +53 -42
- package/dist/commonjs/credential/communicationAccessKeyCredentialPolicy.js.map +7 -1
- package/dist/commonjs/credential/communicationAuthPolicy.js +39 -26
- package/dist/commonjs/credential/communicationAuthPolicy.js.map +7 -1
- package/dist/commonjs/credential/connectionString.js +39 -28
- package/dist/commonjs/credential/connectionString.js.map +7 -1
- package/dist/commonjs/credential/index.js +28 -10
- package/dist/commonjs/credential/index.js.map +7 -1
- package/dist/commonjs/entraTokenCredential.d.ts.map +1 -1
- package/dist/commonjs/entraTokenCredential.js +137 -113
- package/dist/commonjs/entraTokenCredential.js.map +7 -1
- package/dist/commonjs/identifierModelSerializer.js +172 -159
- package/dist/commonjs/identifierModelSerializer.js.map +7 -1
- package/dist/commonjs/identifierModels.js +183 -205
- package/dist/commonjs/identifierModels.js.map +7 -1
- package/dist/commonjs/index.d.ts +4 -3
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +40 -12
- package/dist/commonjs/index.js.map +7 -1
- package/dist/commonjs/logger.d.ts +3 -0
- package/dist/commonjs/logger.d.ts.map +1 -0
- package/dist/commonjs/logger.js +29 -0
- package/dist/commonjs/logger.js.map +7 -0
- package/dist/commonjs/staticTokenCredential.js +36 -20
- package/dist/commonjs/staticTokenCredential.js.map +7 -1
- package/dist/commonjs/tokenParser.d.ts +9 -1
- package/dist/commonjs/tokenParser.d.ts.map +1 -1
- package/dist/commonjs/tokenParser.js +71 -13
- package/dist/commonjs/tokenParser.js.map +7 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/esm/autoRefreshTokenCredential.d.ts +20 -4
- package/dist/esm/autoRefreshTokenCredential.d.ts.map +1 -1
- package/dist/esm/autoRefreshTokenCredential.js +13 -4
- package/dist/esm/autoRefreshTokenCredential.js.map +1 -1
- package/dist/esm/azureCommunicationTokenCredential.d.ts +3 -2
- package/dist/esm/azureCommunicationTokenCredential.d.ts.map +1 -1
- package/dist/esm/azureCommunicationTokenCredential.js +3 -2
- package/dist/esm/azureCommunicationTokenCredential.js.map +1 -1
- package/dist/esm/credential/communicationAccessKeyCredentialPolicy.d.ts.map +1 -1
- package/dist/esm/credential/communicationAccessKeyCredentialPolicy.js +6 -10
- package/dist/esm/credential/communicationAccessKeyCredentialPolicy.js.map +1 -1
- package/dist/esm/entraTokenCredential.d.ts.map +1 -1
- package/dist/esm/entraTokenCredential.js +12 -7
- package/dist/esm/entraTokenCredential.js.map +1 -1
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logger.d.ts +3 -0
- package/dist/esm/logger.d.ts.map +1 -0
- package/dist/esm/logger.js +6 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/tokenParser.d.ts +9 -1
- package/dist/esm/tokenParser.d.ts.map +1 -1
- package/dist/esm/tokenParser.js +64 -3
- package/dist/esm/tokenParser.js.map +1 -1
- package/dist/react-native/autoRefreshTokenCredential.d.ts +20 -4
- package/dist/react-native/autoRefreshTokenCredential.d.ts.map +1 -1
- package/dist/react-native/autoRefreshTokenCredential.js +13 -4
- package/dist/react-native/autoRefreshTokenCredential.js.map +1 -1
- package/dist/react-native/azureCommunicationTokenCredential.d.ts +3 -2
- package/dist/react-native/azureCommunicationTokenCredential.d.ts.map +1 -1
- package/dist/react-native/azureCommunicationTokenCredential.js +3 -2
- package/dist/react-native/azureCommunicationTokenCredential.js.map +1 -1
- package/dist/react-native/credential/communicationAccessKeyCredentialPolicy.d.ts.map +1 -1
- package/dist/react-native/credential/communicationAccessKeyCredentialPolicy.js +6 -10
- package/dist/react-native/credential/communicationAccessKeyCredentialPolicy.js.map +1 -1
- package/dist/react-native/entraTokenCredential.d.ts.map +1 -1
- package/dist/react-native/entraTokenCredential.js +12 -7
- package/dist/react-native/entraTokenCredential.js.map +1 -1
- package/dist/react-native/index.d.ts +4 -3
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +1 -0
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/logger.d.ts +3 -0
- package/dist/react-native/logger.d.ts.map +1 -0
- package/dist/react-native/logger.js +6 -0
- package/dist/react-native/logger.js.map +1 -0
- package/dist/react-native/tokenParser.d.ts +9 -1
- package/dist/react-native/tokenParser.d.ts.map +1 -1
- package/dist/react-native/tokenParser.js +64 -3
- package/dist/react-native/tokenParser.js.map +1 -1
- package/package.json +34 -41
- package/dist/browser/credential/cryptoUtils-browser.d.mts.map +0 -1
- package/dist/browser/credential/cryptoUtils-browser.mjs.map +0 -1
- package/dist/browser/credential/cryptoUtils.d.ts +0 -3
- package/dist/browser/credential/cryptoUtils.js +0 -19
- package/dist/browser/credential/encodeUtils-browser.d.mts +0 -4
- package/dist/browser/credential/encodeUtils-browser.d.mts.map +0 -1
- package/dist/browser/credential/encodeUtils-browser.mjs +0 -19
- package/dist/browser/credential/encodeUtils-browser.mjs.map +0 -1
- package/dist/commonjs/credential/cryptoUtils.d.ts +0 -3
- package/dist/commonjs/credential/cryptoUtils.d.ts.map +0 -1
- package/dist/commonjs/credential/cryptoUtils.js +0 -14
- package/dist/commonjs/credential/cryptoUtils.js.map +0 -1
- package/dist/esm/credential/cryptoUtils.d.ts +0 -3
- package/dist/esm/credential/cryptoUtils.d.ts.map +0 -1
- package/dist/esm/credential/cryptoUtils.js +0 -9
- package/dist/esm/credential/cryptoUtils.js.map +0 -1
- package/dist/esm/credential/encodeUtils-browser.d.mts +0 -4
- package/dist/esm/credential/encodeUtils-browser.d.mts.map +0 -1
- package/dist/esm/credential/encodeUtils-browser.mjs +0 -19
- package/dist/esm/credential/encodeUtils-browser.mjs.map +0 -1
- package/dist/react-native/credential/cryptoUtils.d.ts +0 -3
- package/dist/react-native/credential/cryptoUtils.d.ts.map +0 -1
- package/dist/react-native/credential/cryptoUtils.js +0 -9
- package/dist/react-native/credential/cryptoUtils.js.map +0 -1
- package/dist/react-native/credential/encodeUtils-browser.d.mts +0 -4
- package/dist/react-native/credential/encodeUtils-browser.d.mts.map +0 -1
- package/dist/react-native/credential/encodeUtils-browser.mjs +0 -19
- package/dist/react-native/credential/encodeUtils-browser.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenParser.js","sourceRoot":"","sources":["../../src/tokenParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"tokenParser.js","sourceRoot":"","sources":["../../src/tokenParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAMrC;;;;;GAKG;AACH,MAAM,8CAA8C,GAAG,EAAE,GAAG,EAAE,CAAC;AAE/D,IAAI,8BAA8B,GAAG,KAAK,CAAC;AAE3C,8FAA8F;AAC9F,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAc,EAAwB,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ;IACzB,KAAK,KAAK,IAAI;IACd,OAAQ,KAAqB,CAAC,KAAK,KAAK,QAAQ;IAC/C,KAAqB,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;IACvC,OAAQ,KAAqB,CAAC,kBAAkB,KAAK,QAAQ;IAC7D,MAAM,CAAC,QAAQ,CAAE,KAAqB,CAAC,kBAAkB,CAAC,CAAC;AAE7D;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,CACzB,KAAa,EACb,uCAA+C,EAClC,EAAE;IACf,IACE,CAAC,MAAM,CAAC,QAAQ,CAAC,uCAAuC,CAAC;QACzD,uCAAuC,IAAI,CAAC,EAC5C,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IACxF,CAAC;IACD,IAAI,CAAC,8BAA8B,EAAE,CAAC;QACpC,8BAA8B,GAAG,IAAI,CAAC;QACtC,MAAM,CAAC,OAAO,CACZ,oFAAoF,uCAAuC,cAAc;YACvI,0HAA0H,CAC7H,CAAC;IACJ,CAAC;IACD,OAAO;QACL,KAAK;QACL,kBAAkB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,uCAAuC,GAAG,IAAI;KAChF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAA2B,EAC3B,0CAAkD,8CAA8C,EACnF,EAAE;IACf,qDAAqD;IACrD,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CACb,4GAA4G,CAC7G,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,0CAA0C;IAC1C,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,CAAW,KAAK,CAAC,CAAC;QAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACpD,OAAO;gBACL,KAAK;gBACL,kBAAkB,EAAE,GAAG,GAAG,IAAI;aAC/B,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,oDAAoD;IACtD,CAAC;IAED,OAAO,kBAAkB,CAAC,KAAK,EAAE,uCAAuC,CAAC,CAAC;AAC5E,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken } from \"@azure/core-auth\";\nimport { jwtDecode } from \"jwt-decode\";\nimport { logger } from \"./logger.js\";\n\ninterface JwtToken {\n exp: number;\n}\n\n/**\n * Default lifetime (in seconds) assumed for an encrypted/undecodable token when no expiry is\n * supplied. Must stay in step with `defaultExpiringSoonInterval` (10 min) in\n * autoRefreshTokenCredential.ts: the \"refresh an opaque token at half-life\" behavior relies on a\n * fresh fallback token immediately landing in the expiring-soon window.\n */\nconst defaultUndecodableTokenExpiryIntervalInSeconds = 10 * 60;\n\nlet undecodableTokenWarningEmitted = false;\n\n/** Type guard for a caller-supplied {@link AccessToken} (carries a valid explicit expiry). */\nexport const isAccessToken = (value: unknown): value is AccessToken =>\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as AccessToken).token === \"string\" &&\n (value as AccessToken).token.length > 0 &&\n typeof (value as AccessToken).expiresOnTimestamp === \"number\" &&\n Number.isFinite((value as AccessToken).expiresOnTimestamp);\n\n/**\n * Accepts a token that can't be decoded (encrypted/opaque, or a JWT without a usable `exp`) and\n * assigns a fallback expiry of `now + undecodableTokenExpiryIntervalInSeconds`. Emits a one-time\n * warning; throws if the interval is not a positive, finite number.\n */\nconst resolveOpaqueToken = (\n token: string,\n undecodableTokenExpiryIntervalInSeconds: number,\n): AccessToken => {\n if (\n !Number.isFinite(undecodableTokenExpiryIntervalInSeconds) ||\n undecodableTokenExpiryIntervalInSeconds <= 0\n ) {\n throw new Error(\"undecodableTokenExpiryIntervalInSeconds must be a positive number.\");\n }\n if (!undecodableTokenWarningEmitted) {\n undecodableTokenWarningEmitted = true;\n logger.warning(\n `Received a token that could not be decoded; treating it as opaque and assuming a ${undecodableTokenExpiryIntervalInSeconds}s lifetime. ` +\n `Supply an AccessToken with an explicit expiry (e.g. from the token response 'expires_in') to control refresh scheduling.`,\n );\n }\n return {\n token,\n expiresOnTimestamp: Date.now() + undecodableTokenExpiryIntervalInSeconds * 1000,\n };\n};\n\n/**\n * Resolves a token into an {@link AccessToken}. Expiry is taken from a caller-supplied\n * `AccessToken` if present, otherwise from the JWT `exp` claim. A token that cannot be decoded\n * (e.g. an encrypted/opaque token) or that lacks a usable `exp` is accepted as-is with a fallback\n * expiry of `now + undecodableTokenExpiryIntervalInSeconds`; an empty/blank token throws.\n */\nexport const parseToken = (\n token: string | AccessToken,\n undecodableTokenExpiryIntervalInSeconds: number = defaultUndecodableTokenExpiryIntervalInSeconds,\n): AccessToken => {\n // Caller supplied an explicit expiry — use it as-is.\n if (isAccessToken(token)) {\n return token;\n }\n if (typeof token !== \"string\") {\n throw new Error(\n \"Invalid token: expected a string or an AccessToken with a non-empty token and a finite expiresOnTimestamp.\",\n );\n }\n if (token.trim().length === 0) {\n throw new Error(\"Invalid token: token must not be empty.\");\n }\n\n // Prefer the expiry from a decodable JWT.\n try {\n const { exp } = jwtDecode<JwtToken>(token);\n if (typeof exp === \"number\" && Number.isFinite(exp)) {\n return {\n token,\n expiresOnTimestamp: exp * 1000,\n };\n }\n } catch {\n // Not decodable — treated as an opaque token below.\n }\n\n return resolveOpaqueToken(token, undecodableTokenExpiryIntervalInSeconds);\n};\n"]}
|
|
@@ -6,25 +6,41 @@ import type { AccessToken } from "@azure/core-auth";
|
|
|
6
6
|
*/
|
|
7
7
|
export interface CommunicationTokenRefreshOptions {
|
|
8
8
|
/**
|
|
9
|
-
* Callback
|
|
9
|
+
* Callback that returns a token acquired from the Communication Identity API.
|
|
10
10
|
* The returned token must be valid (expiration date must be in the future).
|
|
11
|
+
*
|
|
12
|
+
* Return a `string` to have the expiry read from the JWT, or an `AccessToken`
|
|
13
|
+
* to supply the expiry explicitly (required for encrypted access tokens that
|
|
14
|
+
* cannot be decoded).
|
|
11
15
|
*/
|
|
12
|
-
tokenRefresher: (abortSignal?: AbortSignalLike) => Promise<string>;
|
|
16
|
+
tokenRefresher: (abortSignal?: AbortSignalLike) => Promise<string | AccessToken>;
|
|
13
17
|
/**
|
|
14
|
-
* Optional token to initialize.
|
|
18
|
+
* Optional token to initialize. May be a `string` or an `AccessToken` carrying
|
|
19
|
+
* an explicit expiry.
|
|
15
20
|
*/
|
|
16
|
-
token?: string;
|
|
21
|
+
token?: string | AccessToken;
|
|
17
22
|
/**
|
|
18
23
|
* Indicates whether the token should be proactively renewed prior to expiry or only renew on demand.
|
|
19
24
|
* By default false.
|
|
20
25
|
*/
|
|
21
26
|
refreshProactively?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Lifetime, in seconds, assumed for a returned token that cannot be decoded and
|
|
29
|
+
* carries no explicit expiry (e.g. an encrypted access token). Defaults to 600 (10 minutes).
|
|
30
|
+
*
|
|
31
|
+
* Set this to your tokens' real lifetime. It is not capped: a value larger than the token's
|
|
32
|
+
* actual lifetime means the credential refreshes later than it should and the service will
|
|
33
|
+
* reject the expired token. To avoid guessing, prefer returning an `AccessToken` with an
|
|
34
|
+
* explicit `expiresOnTimestamp` (e.g. derived from the token response's `expires_in`).
|
|
35
|
+
*/
|
|
36
|
+
undecodableTokenExpiryIntervalInSeconds?: number;
|
|
22
37
|
}
|
|
23
38
|
export declare class AutoRefreshTokenCredential implements TokenCredential {
|
|
24
39
|
private readonly refresh;
|
|
25
40
|
private readonly refreshProactively;
|
|
26
41
|
private readonly expiringSoonIntervalInMs;
|
|
27
42
|
private readonly refreshAfterLifetimePercentage;
|
|
43
|
+
private readonly undecodableTokenExpiryIntervalInSeconds;
|
|
28
44
|
private currentToken;
|
|
29
45
|
private activeTimeout;
|
|
30
46
|
private activeTokenFetching;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autoRefreshTokenCredential.d.ts","sourceRoot":"","sources":["../../src/autoRefreshTokenCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C
|
|
1
|
+
{"version":3,"file":"autoRefreshTokenCredential.d.ts","sourceRoot":"","sources":["../../src/autoRefreshTokenCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C;;;;;;;OAOG;IACH,cAAc,EAAE,CAAC,WAAW,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC;IAEjF;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAE7B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;;;OAQG;IACH,uCAAuC,CAAC,EAAE,MAAM,CAAC;CAClD;AASD,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmE;IAC3F,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAU;IAC7C,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAuC;IAChF,OAAO,CAAC,QAAQ,CAAC,8BAA8B,CAAyC;IACxF,OAAO,CAAC,QAAQ,CAAC,uCAAuC,CAAqB;IAE7E,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,aAAa,CAA4C;IACjE,OAAO,CAAC,mBAAmB,CAA8C;IACzE,OAAO,CAAC,mBAAmB,CAA8B;IACzD,OAAO,CAAC,QAAQ,CAAS;gBAEb,WAAW,EAAE,gCAAgC;IAgB5C,QAAQ,CAAC,OAAO,CAAC,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC;IAa5E,OAAO,IAAI,IAAI;YAUR,wBAAwB;YAexB,yBAAyB;YAazB,YAAY;IAc1B,OAAO,CAAC,eAAe;IAqBvB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,mBAAmB;CAG5B"}
|
|
@@ -1,109 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var autoRefreshTokenCredential_exports = {};
|
|
19
|
+
__export(autoRefreshTokenCredential_exports, {
|
|
20
|
+
AutoRefreshTokenCredential: () => AutoRefreshTokenCredential
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(autoRefreshTokenCredential_exports);
|
|
23
|
+
var import_tokenParser = require("./tokenParser.js");
|
|
7
24
|
const expiredToken = { token: "", expiresOnTimestamp: -10 };
|
|
8
|
-
const minutesToMs = (minutes) => minutes *
|
|
25
|
+
const minutesToMs = (minutes) => minutes * 1e3 * 60;
|
|
9
26
|
const defaultExpiringSoonInterval = minutesToMs(10);
|
|
10
27
|
const defaultRefreshAfterLifetimePercentage = 0.5;
|
|
11
28
|
class AutoRefreshTokenCredential {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
refresh;
|
|
30
|
+
refreshProactively;
|
|
31
|
+
expiringSoonIntervalInMs = defaultExpiringSoonInterval;
|
|
32
|
+
refreshAfterLifetimePercentage = defaultRefreshAfterLifetimePercentage;
|
|
33
|
+
undecodableTokenExpiryIntervalInSeconds;
|
|
34
|
+
currentToken;
|
|
35
|
+
activeTimeout;
|
|
36
|
+
activeTokenFetching = null;
|
|
37
|
+
activeTokenUpdating = null;
|
|
38
|
+
disposed = false;
|
|
39
|
+
constructor(refreshArgs) {
|
|
40
|
+
const { tokenRefresher, token, refreshProactively, undecodableTokenExpiryIntervalInSeconds } = refreshArgs;
|
|
41
|
+
this.refresh = tokenRefresher;
|
|
42
|
+
this.undecodableTokenExpiryIntervalInSeconds = undecodableTokenExpiryIntervalInSeconds;
|
|
43
|
+
this.currentToken = token ? (0, import_tokenParser.parseToken)(token, this.undecodableTokenExpiryIntervalInSeconds) : expiredToken;
|
|
44
|
+
this.refreshProactively = refreshProactively ?? false;
|
|
45
|
+
if (this.refreshProactively) {
|
|
46
|
+
this.scheduleRefresh();
|
|
29
47
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (!this.isTokenValid(this.currentToken)) {
|
|
35
|
-
const updatePromise = this.updateTokenAndReschedule(options?.abortSignal);
|
|
36
|
-
await updatePromise;
|
|
37
|
-
}
|
|
38
|
-
return this.currentToken;
|
|
48
|
+
}
|
|
49
|
+
async getToken(options) {
|
|
50
|
+
if (!this.isTokenExpiringSoon(this.currentToken)) {
|
|
51
|
+
return this.currentToken;
|
|
39
52
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.activeTokenUpdating = null;
|
|
44
|
-
this.currentToken = expiredToken;
|
|
45
|
-
if (this.activeTimeout) {
|
|
46
|
-
clearTimeout(this.activeTimeout);
|
|
47
|
-
}
|
|
53
|
+
if (!this.isTokenValid(this.currentToken)) {
|
|
54
|
+
const updatePromise = this.updateTokenAndReschedule(options?.abortSignal);
|
|
55
|
+
await updatePromise;
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.activeTokenUpdating = null;
|
|
59
|
-
}
|
|
57
|
+
return this.currentToken;
|
|
58
|
+
}
|
|
59
|
+
dispose() {
|
|
60
|
+
this.disposed = true;
|
|
61
|
+
this.activeTokenFetching = null;
|
|
62
|
+
this.activeTokenUpdating = null;
|
|
63
|
+
this.currentToken = expiredToken;
|
|
64
|
+
if (this.activeTimeout !== void 0) {
|
|
65
|
+
clearTimeout(this.activeTimeout);
|
|
60
66
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
this.currentToken = newToken;
|
|
67
|
-
if (this.refreshProactively) {
|
|
68
|
-
this.scheduleRefresh();
|
|
69
|
-
}
|
|
67
|
+
}
|
|
68
|
+
async updateTokenAndReschedule(abortSignal) {
|
|
69
|
+
if (this.disposed) {
|
|
70
|
+
return;
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!this.activeTokenFetching) {
|
|
74
|
-
this.activeTokenFetching = this.refresh(abortSignal);
|
|
75
|
-
}
|
|
76
|
-
return (0, tokenParser_js_1.parseToken)(await this.activeTokenFetching);
|
|
77
|
-
}
|
|
78
|
-
finally {
|
|
79
|
-
this.activeTokenFetching = null;
|
|
80
|
-
}
|
|
72
|
+
if (this.activeTokenUpdating) {
|
|
73
|
+
return this.activeTokenUpdating;
|
|
81
74
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
clearTimeout(this.activeTimeout);
|
|
88
|
-
}
|
|
89
|
-
const tokenTtlInMs = this.currentToken.expiresOnTimestamp - Date.now();
|
|
90
|
-
let timespanInMs = null;
|
|
91
|
-
if (this.isTokenExpiringSoon(this.currentToken)) {
|
|
92
|
-
// Schedule the next refresh for when it reaches a certain percentage of the remaining lifetime.
|
|
93
|
-
timespanInMs = tokenTtlInMs * this.refreshAfterLifetimePercentage;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
// Schedule the next refresh for when it gets in to the soon-to-expire window.
|
|
97
|
-
timespanInMs = tokenTtlInMs - this.expiringSoonIntervalInMs;
|
|
98
|
-
}
|
|
99
|
-
this.activeTimeout = setTimeout(() => this.updateTokenAndReschedule(), timespanInMs);
|
|
75
|
+
this.activeTokenUpdating = this.refreshTokenAndReschedule(abortSignal);
|
|
76
|
+
try {
|
|
77
|
+
await this.activeTokenUpdating;
|
|
78
|
+
} finally {
|
|
79
|
+
this.activeTokenUpdating = null;
|
|
100
80
|
}
|
|
101
|
-
|
|
102
|
-
|
|
81
|
+
}
|
|
82
|
+
async refreshTokenAndReschedule(abortSignal) {
|
|
83
|
+
const newToken = await this.refreshToken(abortSignal);
|
|
84
|
+
if (!this.isTokenValid(newToken)) {
|
|
85
|
+
throw new Error("The token returned from the tokenRefresher is expired.");
|
|
103
86
|
}
|
|
104
|
-
|
|
105
|
-
|
|
87
|
+
this.currentToken = newToken;
|
|
88
|
+
if (this.refreshProactively) {
|
|
89
|
+
this.scheduleRefresh();
|
|
106
90
|
}
|
|
91
|
+
}
|
|
92
|
+
async refreshToken(abortSignal) {
|
|
93
|
+
try {
|
|
94
|
+
if (!this.activeTokenFetching) {
|
|
95
|
+
this.activeTokenFetching = this.refresh(abortSignal);
|
|
96
|
+
}
|
|
97
|
+
return (0, import_tokenParser.parseToken)(
|
|
98
|
+
await this.activeTokenFetching,
|
|
99
|
+
this.undecodableTokenExpiryIntervalInSeconds
|
|
100
|
+
);
|
|
101
|
+
} finally {
|
|
102
|
+
this.activeTokenFetching = null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
scheduleRefresh() {
|
|
106
|
+
if (this.disposed) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (this.activeTimeout) {
|
|
110
|
+
clearTimeout(this.activeTimeout);
|
|
111
|
+
}
|
|
112
|
+
const tokenTtlInMs = this.currentToken.expiresOnTimestamp - Date.now();
|
|
113
|
+
let timespanInMs = null;
|
|
114
|
+
if (this.isTokenExpiringSoon(this.currentToken)) {
|
|
115
|
+
timespanInMs = tokenTtlInMs * this.refreshAfterLifetimePercentage;
|
|
116
|
+
} else {
|
|
117
|
+
timespanInMs = tokenTtlInMs - this.expiringSoonIntervalInMs;
|
|
118
|
+
}
|
|
119
|
+
this.activeTimeout = setTimeout(() => this.updateTokenAndReschedule(), timespanInMs);
|
|
120
|
+
}
|
|
121
|
+
isTokenValid(token) {
|
|
122
|
+
return token && Date.now() < token.expiresOnTimestamp;
|
|
123
|
+
}
|
|
124
|
+
isTokenExpiringSoon(token) {
|
|
125
|
+
return !token || Date.now() >= token.expiresOnTimestamp - this.expiringSoonIntervalInMs;
|
|
126
|
+
}
|
|
107
127
|
}
|
|
108
|
-
|
|
109
|
-
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
AutoRefreshTokenCredential
|
|
131
|
+
});
|
|
132
|
+
//# sourceMappingURL=autoRefreshTokenCredential.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/autoRefreshTokenCredential.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n CommunicationGetTokenOptions,\n TokenCredential,\n} from \"./communicationTokenCredential.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { AccessToken } from \"@azure/core-auth\";\nimport { parseToken } from \"./tokenParser.js\";\n\n/**\n * Options for auto-refreshing a Communication Token credential.\n */\nexport interface CommunicationTokenRefreshOptions {\n /**\n * Callback that returns a token acquired from the Communication Identity API.\n * The returned token must be valid (expiration date must be in the future).\n *\n * Return a `string` to have the expiry read from the JWT, or an `AccessToken`\n * to supply the expiry explicitly (required for encrypted access tokens that\n * cannot be decoded).\n */\n tokenRefresher: (abortSignal?: AbortSignalLike) => Promise<string | AccessToken>;\n\n /**\n * Optional token to initialize. May be a `string` or an `AccessToken` carrying\n * an explicit expiry.\n */\n token?: string | AccessToken;\n\n /**\n * Indicates whether the token should be proactively renewed prior to expiry or only renew on demand.\n * By default false.\n */\n refreshProactively?: boolean;\n\n /**\n * Lifetime, in seconds, assumed for a returned token that cannot be decoded and\n * carries no explicit expiry (e.g. an encrypted access token). Defaults to 600 (10 minutes).\n *\n * Set this to your tokens' real lifetime. It is not capped: a value larger than the token's\n * actual lifetime means the credential refreshes later than it should and the service will\n * reject the expired token. To avoid guessing, prefer returning an `AccessToken` with an\n * explicit `expiresOnTimestamp` (e.g. derived from the token response's `expires_in`).\n */\n undecodableTokenExpiryIntervalInSeconds?: number;\n}\n\nconst expiredToken = { token: \"\", expiresOnTimestamp: -10 };\nconst minutesToMs = (minutes: number): number => minutes * 1000 * 60;\n// Must stay in step with `defaultUndecodableTokenExpiryIntervalInSeconds` (600s) in tokenParser.ts \u2014\n// an opaque token's fallback expiry is expected to land in this expiring-soon window.\nconst defaultExpiringSoonInterval = minutesToMs(10);\nconst defaultRefreshAfterLifetimePercentage = 0.5;\n\nexport class AutoRefreshTokenCredential implements TokenCredential {\n private readonly refresh: (abortSignal?: AbortSignalLike) => Promise<string | AccessToken>;\n private readonly refreshProactively: boolean;\n private readonly expiringSoonIntervalInMs: number = defaultExpiringSoonInterval;\n private readonly refreshAfterLifetimePercentage = defaultRefreshAfterLifetimePercentage;\n private readonly undecodableTokenExpiryIntervalInSeconds: number | undefined;\n\n private currentToken: AccessToken;\n private activeTimeout: ReturnType<typeof setTimeout> | undefined;\n private activeTokenFetching: Promise<string | AccessToken> | null = null;\n private activeTokenUpdating: Promise<void> | null = null;\n private disposed = false;\n\n constructor(refreshArgs: CommunicationTokenRefreshOptions) {\n const { tokenRefresher, token, refreshProactively, undecodableTokenExpiryIntervalInSeconds } =\n refreshArgs;\n\n this.refresh = tokenRefresher;\n this.undecodableTokenExpiryIntervalInSeconds = undecodableTokenExpiryIntervalInSeconds;\n this.currentToken = token\n ? parseToken(token, this.undecodableTokenExpiryIntervalInSeconds)\n : expiredToken;\n this.refreshProactively = refreshProactively ?? false;\n\n if (this.refreshProactively) {\n this.scheduleRefresh();\n }\n }\n\n public async getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken> {\n if (!this.isTokenExpiringSoon(this.currentToken)) {\n return this.currentToken;\n }\n\n if (!this.isTokenValid(this.currentToken)) {\n const updatePromise = this.updateTokenAndReschedule(options?.abortSignal);\n await updatePromise;\n }\n\n return this.currentToken;\n }\n\n public dispose(): void {\n this.disposed = true;\n this.activeTokenFetching = null;\n this.activeTokenUpdating = null;\n this.currentToken = expiredToken;\n if (this.activeTimeout !== undefined) {\n clearTimeout(this.activeTimeout);\n }\n }\n\n private async updateTokenAndReschedule(abortSignal?: AbortSignalLike): Promise<void> {\n if (this.disposed) {\n return;\n }\n if (this.activeTokenUpdating) {\n return this.activeTokenUpdating;\n }\n this.activeTokenUpdating = this.refreshTokenAndReschedule(abortSignal);\n try {\n await this.activeTokenUpdating;\n } finally {\n this.activeTokenUpdating = null;\n }\n }\n\n private async refreshTokenAndReschedule(abortSignal?: AbortSignalLike): Promise<void> {\n const newToken = await this.refreshToken(abortSignal);\n\n if (!this.isTokenValid(newToken)) {\n throw new Error(\"The token returned from the tokenRefresher is expired.\");\n }\n\n this.currentToken = newToken;\n if (this.refreshProactively) {\n this.scheduleRefresh();\n }\n }\n\n private async refreshToken(abortSignal?: AbortSignalLike): Promise<AccessToken> {\n try {\n if (!this.activeTokenFetching) {\n this.activeTokenFetching = this.refresh(abortSignal);\n }\n return parseToken(\n await this.activeTokenFetching,\n this.undecodableTokenExpiryIntervalInSeconds,\n );\n } finally {\n this.activeTokenFetching = null;\n }\n }\n\n private scheduleRefresh(): void {\n if (this.disposed) {\n return;\n }\n if (this.activeTimeout) {\n clearTimeout(this.activeTimeout);\n }\n const tokenTtlInMs = this.currentToken.expiresOnTimestamp - Date.now();\n let timespanInMs = null;\n\n if (this.isTokenExpiringSoon(this.currentToken)) {\n // Schedule the next refresh for when it reaches a certain percentage of the remaining lifetime.\n timespanInMs = tokenTtlInMs * this.refreshAfterLifetimePercentage;\n } else {\n // Schedule the next refresh for when it gets in to the soon-to-expire window.\n timespanInMs = tokenTtlInMs - this.expiringSoonIntervalInMs;\n }\n\n this.activeTimeout = setTimeout(() => this.updateTokenAndReschedule(), timespanInMs);\n }\n\n private isTokenValid(token: AccessToken): boolean {\n return token && Date.now() < token.expiresOnTimestamp;\n }\n\n private isTokenExpiringSoon(token: AccessToken): boolean {\n return !token || Date.now() >= token.expiresOnTimestamp - this.expiringSoonIntervalInMs;\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -10,9 +10,10 @@ export declare class AzureCommunicationTokenCredential implements CommunicationT
|
|
|
10
10
|
private disposed;
|
|
11
11
|
/**
|
|
12
12
|
* Creates an instance of CommunicationTokenCredential with a static token and no proactive refreshing.
|
|
13
|
-
* @param token - A user access token issued by Communication Services.
|
|
13
|
+
* @param token - A user access token issued by Communication Services. Pass an `AccessToken`
|
|
14
|
+
* to supply the expiry explicitly when the token cannot be decoded (e.g. an encrypted token).
|
|
14
15
|
*/
|
|
15
|
-
constructor(token: string);
|
|
16
|
+
constructor(token: string | AccessToken);
|
|
16
17
|
/**
|
|
17
18
|
* Creates an instance of CommunicationTokenCredential with a lambda to get a token and options
|
|
18
19
|
* to configure proactive refreshing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"azureCommunicationTokenCredential.d.ts","sourceRoot":"","sources":["../../src/azureCommunicationTokenCredential.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,gCAAgC,EACtC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAE7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EACL,KAAK,wCAAwC,EAE9C,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AAEH,qBAAa,iCAAkC,YAAW,4BAA4B;IACpF,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAClD,OAAO,CAAC,QAAQ,CAAS;IAEzB
|
|
1
|
+
{"version":3,"file":"azureCommunicationTokenCredential.d.ts","sourceRoot":"","sources":["../../src/azureCommunicationTokenCredential.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,gCAAgC,EACtC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAE7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EACL,KAAK,wCAAwC,EAE9C,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AAEH,qBAAa,iCAAkC,YAAW,4BAA4B;IACpF,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAClD,OAAO,CAAC,QAAQ,CAAS;IAEzB;;;;OAIG;gBACS,KAAK,EAAE,MAAM,GAAG,WAAW;IACvC;;;;OAIG;gBACS,cAAc,EAAE,gCAAgC;IAC5D;;;OAGG;gBACS,YAAY,EAAE,wCAAwC;IAsBlE;;;OAGG;IACU,QAAQ,CAAC,OAAO,CAAC,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC;IAOnF;;OAEG;IACI,OAAO,IAAI,IAAI;IAKtB,OAAO,CAAC,eAAe;CAKxB"}
|
|
@@ -1,51 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var azureCommunicationTokenCredential_exports = {};
|
|
19
|
+
__export(azureCommunicationTokenCredential_exports, {
|
|
20
|
+
AzureCommunicationTokenCredential: () => AzureCommunicationTokenCredential
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(azureCommunicationTokenCredential_exports);
|
|
23
|
+
var import_autoRefreshTokenCredential = require("./autoRefreshTokenCredential.js");
|
|
24
|
+
var import_staticTokenCredential = require("./staticTokenCredential.js");
|
|
25
|
+
var import_tokenParser = require("./tokenParser.js");
|
|
26
|
+
var import_entraTokenCredential = require("./entraTokenCredential.js");
|
|
13
27
|
class AzureCommunicationTokenCredential {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
28
|
+
tokenCredential;
|
|
29
|
+
disposed = false;
|
|
30
|
+
constructor(tokenOrRefreshOptionsOrEntraOptions) {
|
|
31
|
+
if (typeof tokenOrRefreshOptionsOrEntraOptions === "string" || (0, import_tokenParser.isAccessToken)(tokenOrRefreshOptionsOrEntraOptions)) {
|
|
32
|
+
this.tokenCredential = new import_staticTokenCredential.StaticTokenCredential(
|
|
33
|
+
(0, import_tokenParser.parseToken)(tokenOrRefreshOptionsOrEntraOptions)
|
|
34
|
+
);
|
|
35
|
+
} else if ("tokenRefresher" in tokenOrRefreshOptionsOrEntraOptions) {
|
|
36
|
+
this.tokenCredential = new import_autoRefreshTokenCredential.AutoRefreshTokenCredential(tokenOrRefreshOptionsOrEntraOptions);
|
|
37
|
+
} else {
|
|
38
|
+
this.tokenCredential = new import_entraTokenCredential.EntraTokenCredential(tokenOrRefreshOptionsOrEntraOptions);
|
|
26
39
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets an `AccessToken` for the user. Throws if already disposed.
|
|
43
|
+
* @param abortSignal - An implementation of `AbortSignalLike` to cancel the operation.
|
|
44
|
+
*/
|
|
45
|
+
async getToken(options) {
|
|
46
|
+
this.throwIfDisposed();
|
|
47
|
+
const token = await this.tokenCredential.getToken(options);
|
|
48
|
+
this.throwIfDisposed();
|
|
49
|
+
return token;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Disposes the CommunicationTokenCredential and cancels any internal auto-refresh operation.
|
|
53
|
+
*/
|
|
54
|
+
dispose() {
|
|
55
|
+
this.disposed = true;
|
|
56
|
+
this.tokenCredential.dispose();
|
|
57
|
+
}
|
|
58
|
+
throwIfDisposed() {
|
|
59
|
+
if (this.disposed) {
|
|
60
|
+
throw new Error("User credential is disposed");
|
|
48
61
|
}
|
|
62
|
+
}
|
|
49
63
|
}
|
|
50
|
-
|
|
51
|
-
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
AzureCommunicationTokenCredential
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=azureCommunicationTokenCredential.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/azureCommunicationTokenCredential.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n AutoRefreshTokenCredential,\n type CommunicationTokenRefreshOptions,\n} from \"./autoRefreshTokenCredential.js\";\nimport type {\n CommunicationGetTokenOptions,\n CommunicationTokenCredential,\n TokenCredential,\n} from \"./communicationTokenCredential.js\";\nimport type { AccessToken } from \"@azure/core-auth\";\nimport { StaticTokenCredential } from \"./staticTokenCredential.js\";\nimport { isAccessToken, parseToken } from \"./tokenParser.js\";\nimport {\n type EntraCommunicationTokenCredentialOptions,\n EntraTokenCredential,\n} from \"./entraTokenCredential.js\";\n\n/**\n * The CommunicationTokenCredential implementation with support for proactive token refresh.\n */\n\nexport class AzureCommunicationTokenCredential implements CommunicationTokenCredential {\n private readonly tokenCredential: TokenCredential;\n private disposed = false;\n\n /**\n * Creates an instance of CommunicationTokenCredential with a static token and no proactive refreshing.\n * @param token - A user access token issued by Communication Services. Pass an `AccessToken`\n * to supply the expiry explicitly when the token cannot be decoded (e.g. an encrypted token).\n */\n constructor(token: string | AccessToken);\n /**\n * Creates an instance of CommunicationTokenCredential with a lambda to get a token and options\n * to configure proactive refreshing.\n * @param refreshOptions - Options to configure refresh and opt-in to proactive refreshing.\n */\n constructor(refreshOptions: CommunicationTokenRefreshOptions);\n /**\n * Creates an instance of CommunicationTokenCredential with an Entra ID token credential. In most cases, you might want to use InteractiveBrowserCredential to sign in your user.\n * @param entraOptions - Options to configure the Entra ID token credential.\n */\n constructor(entraOptions: EntraCommunicationTokenCredentialOptions);\n constructor(\n tokenOrRefreshOptionsOrEntraOptions:\n | string\n | AccessToken\n | CommunicationTokenRefreshOptions\n | EntraCommunicationTokenCredentialOptions,\n ) {\n if (\n typeof tokenOrRefreshOptionsOrEntraOptions === \"string\" ||\n isAccessToken(tokenOrRefreshOptionsOrEntraOptions)\n ) {\n this.tokenCredential = new StaticTokenCredential(\n parseToken(tokenOrRefreshOptionsOrEntraOptions),\n );\n } else if (\"tokenRefresher\" in tokenOrRefreshOptionsOrEntraOptions) {\n this.tokenCredential = new AutoRefreshTokenCredential(tokenOrRefreshOptionsOrEntraOptions);\n } else {\n this.tokenCredential = new EntraTokenCredential(tokenOrRefreshOptionsOrEntraOptions);\n }\n }\n\n /**\n * Gets an `AccessToken` for the user. Throws if already disposed.\n * @param abortSignal - An implementation of `AbortSignalLike` to cancel the operation.\n */\n public async getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken> {\n this.throwIfDisposed();\n const token = await this.tokenCredential.getToken(options);\n this.throwIfDisposed();\n return token;\n }\n\n /**\n * Disposes the CommunicationTokenCredential and cancels any internal auto-refresh operation.\n */\n public dispose(): void {\n this.disposed = true;\n this.tokenCredential.dispose();\n }\n\n private throwIfDisposed(): void {\n if (this.disposed) {\n throw new Error(\"User credential is disposed\");\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wCAGO;AAOP,mCAAsC;AACtC,yBAA0C;AAC1C,kCAGO;AAMA,MAAM,kCAA0E;AAAA,EACpE;AAAA,EACT,WAAW;AAAA,EAmBnB,YACE,qCAKA;AACA,QACE,OAAO,wCAAwC,gBAC/C,kCAAc,mCAAmC,GACjD;AACA,WAAK,kBAAkB,IAAI;AAAA,YACzB,+BAAW,mCAAmC;AAAA,MAChD;AAAA,IACF,WAAW,oBAAoB,qCAAqC;AAClE,WAAK,kBAAkB,IAAI,6DAA2B,mCAAmC;AAAA,IAC3F,OAAO;AACL,WAAK,kBAAkB,IAAI,iDAAqB,mCAAmC;AAAA,IACrF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,SAAS,SAA8D;AAClF,SAAK,gBAAgB;AACrB,UAAM,QAAQ,MAAM,KAAK,gBAAgB,SAAS,OAAO;AACzD,SAAK,gBAAgB;AACrB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKO,UAAgB;AACrB,SAAK,WAAW;AAChB,SAAK,gBAAgB,QAAQ;AAAA,EAC/B;AAAA,EAEQ,kBAAwB;AAC9B,QAAI,KAAK,UAAU;AACjB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var communicationTokenCredential_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(communicationTokenCredential_exports);
|
|
16
|
+
//# sourceMappingURL=communicationTokenCredential.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/communicationTokenCredential.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { AccessToken } from \"@azure/core-auth\";\n\nexport type TokenCredential = Pick<CommunicationTokenCredential, \"getToken\" | \"dispose\">;\n\n/**\n * Options for `CommunicationTokenCredential`'s `getToken` function.\n */\nexport interface CommunicationGetTokenOptions {\n /**\n * An implementation of `AbortSignalLike` to cancel the operation.\n */\n abortSignal?: AbortSignalLike;\n}\n\n/**\n * The Azure Communication Services token credential.\n */\nexport interface CommunicationTokenCredential {\n /**\n * Gets an `AccessToken` for the user. Throws if already disposed.\n * @param options - Additional options.\n */\n getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken>;\n /**\n * Disposes the CommunicationTokenCredential and cancels any internal auto-refresh operation.\n */\n dispose(): void;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|