@typespec/ts-http-runtime 0.1.0-alpha.20250325.2 → 0.2.0-alpha.20250326.3
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/dist/browser/auth/credentials.d.ts +77 -0
- package/dist/browser/auth/credentials.js +27 -0
- package/dist/browser/auth/credentials.js.map +1 -0
- package/dist/browser/auth/oauth2Flows.d.ts +57 -0
- package/dist/browser/{abort-controller/AbortSignalLike.js → auth/oauth2Flows.js} +1 -1
- package/dist/browser/auth/oauth2Flows.js.map +1 -0
- package/dist/browser/auth/schemes.d.ts +53 -0
- package/dist/{esm/abort-controller/AbortSignalLike.js → browser/auth/schemes.js} +1 -1
- package/dist/browser/auth/schemes.js.map +1 -0
- package/dist/browser/client/clientHelpers.d.ts +1 -20
- package/dist/browser/client/clientHelpers.js +21 -30
- package/dist/browser/client/clientHelpers.js.map +1 -1
- package/dist/browser/client/common.d.ts +13 -15
- package/dist/browser/client/common.js.map +1 -1
- package/dist/browser/client/getClient.d.ts +1 -9
- package/dist/browser/client/getClient.js +8 -16
- package/dist/browser/client/getClient.js.map +1 -1
- package/dist/browser/constants.js +1 -1
- package/dist/browser/constants.js.map +1 -1
- package/dist/browser/index.d.ts +3 -3
- package/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/interfaces.d.ts +10 -2
- package/dist/browser/interfaces.js.map +1 -1
- package/dist/browser/pipelineRequest.d.ts +1 -2
- package/dist/browser/pipelineRequest.js.map +1 -1
- package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
- package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.js +31 -0
- package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
- package/dist/browser/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
- package/dist/browser/policies/auth/basicAuthenticationPolicy.js +31 -0
- package/dist/browser/policies/auth/basicAuthenticationPolicy.js.map +1 -0
- package/dist/browser/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
- package/dist/browser/policies/auth/bearerAuthenticationPolicy.js +31 -0
- package/dist/browser/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
- package/dist/browser/policies/auth/checkInsecureConnection.d.ts +9 -0
- package/dist/browser/policies/auth/checkInsecureConnection.js +50 -0
- package/dist/browser/policies/auth/checkInsecureConnection.js.map +1 -0
- package/dist/browser/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
- package/dist/browser/policies/auth/oauth2AuthenticationPolicy.js +31 -0
- package/dist/browser/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
- package/dist/browser/util/aborterUtils.d.ts +3 -4
- package/dist/browser/util/aborterUtils.js.map +1 -1
- package/dist/browser/util/helpers.d.ts +1 -2
- package/dist/browser/util/helpers.js.map +1 -1
- package/dist/commonjs/auth/credentials.d.ts +77 -0
- package/dist/commonjs/auth/credentials.js +33 -0
- package/dist/commonjs/auth/credentials.js.map +1 -0
- package/dist/commonjs/auth/oauth2Flows.d.ts +57 -0
- package/dist/commonjs/{abort-controller/AbortSignalLike.js → auth/oauth2Flows.js} +1 -1
- package/dist/commonjs/auth/oauth2Flows.js.map +1 -0
- package/dist/commonjs/auth/schemes.d.ts +53 -0
- package/dist/commonjs/auth/schemes.js +5 -0
- package/dist/commonjs/auth/schemes.js.map +1 -0
- package/dist/commonjs/client/clientHelpers.d.ts +1 -20
- package/dist/commonjs/client/clientHelpers.js +21 -31
- package/dist/commonjs/client/clientHelpers.js.map +1 -1
- package/dist/commonjs/client/common.d.ts +13 -15
- package/dist/commonjs/client/common.js.map +1 -1
- package/dist/commonjs/client/getClient.d.ts +1 -9
- package/dist/commonjs/client/getClient.js +8 -16
- package/dist/commonjs/client/getClient.js.map +1 -1
- package/dist/commonjs/constants.js +1 -1
- package/dist/commonjs/constants.js.map +1 -1
- package/dist/commonjs/index.d.ts +3 -3
- package/dist/commonjs/index.js +4 -5
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/interfaces.d.ts +10 -2
- package/dist/commonjs/interfaces.js.map +1 -1
- package/dist/commonjs/pipelineRequest.d.ts +1 -2
- package/dist/commonjs/pipelineRequest.js.map +1 -1
- package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
- package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js +35 -0
- package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
- package/dist/commonjs/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
- package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js +35 -0
- package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js.map +1 -0
- package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
- package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js +35 -0
- package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
- package/dist/commonjs/policies/auth/checkInsecureConnection.d.ts +9 -0
- package/dist/commonjs/policies/auth/checkInsecureConnection.js +53 -0
- package/dist/commonjs/policies/auth/checkInsecureConnection.js.map +1 -0
- package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
- package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js +35 -0
- package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
- package/dist/commonjs/util/aborterUtils.d.ts +3 -4
- package/dist/commonjs/util/aborterUtils.js.map +1 -1
- package/dist/commonjs/util/helpers.d.ts +1 -2
- package/dist/commonjs/util/helpers.js.map +1 -1
- package/dist/esm/auth/credentials.d.ts +77 -0
- package/dist/esm/auth/credentials.js +27 -0
- package/dist/esm/auth/credentials.js.map +1 -0
- package/dist/esm/auth/oauth2Flows.d.ts +57 -0
- package/dist/{react-native/abort-controller/AbortSignalLike.js → esm/auth/oauth2Flows.js} +1 -1
- package/dist/esm/auth/oauth2Flows.js.map +1 -0
- package/dist/esm/auth/schemes.d.ts +53 -0
- package/dist/esm/auth/schemes.js +4 -0
- package/dist/esm/auth/schemes.js.map +1 -0
- package/dist/esm/client/clientHelpers.d.ts +1 -20
- package/dist/esm/client/clientHelpers.js +21 -30
- package/dist/esm/client/clientHelpers.js.map +1 -1
- package/dist/esm/client/common.d.ts +13 -15
- package/dist/esm/client/common.js.map +1 -1
- package/dist/esm/client/getClient.d.ts +1 -9
- package/dist/esm/client/getClient.js +8 -16
- package/dist/esm/client/getClient.js.map +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.d.ts +10 -2
- package/dist/esm/interfaces.js.map +1 -1
- package/dist/esm/pipelineRequest.d.ts +1 -2
- package/dist/esm/pipelineRequest.js.map +1 -1
- package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
- package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.js +31 -0
- package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
- package/dist/esm/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
- package/dist/esm/policies/auth/basicAuthenticationPolicy.js +31 -0
- package/dist/esm/policies/auth/basicAuthenticationPolicy.js.map +1 -0
- package/dist/esm/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
- package/dist/esm/policies/auth/bearerAuthenticationPolicy.js +31 -0
- package/dist/esm/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
- package/dist/esm/policies/auth/checkInsecureConnection.d.ts +9 -0
- package/dist/esm/policies/auth/checkInsecureConnection.js +50 -0
- package/dist/esm/policies/auth/checkInsecureConnection.js.map +1 -0
- package/dist/esm/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
- package/dist/esm/policies/auth/oauth2AuthenticationPolicy.js +31 -0
- package/dist/esm/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
- package/dist/esm/util/aborterUtils.d.ts +3 -4
- package/dist/esm/util/aborterUtils.js.map +1 -1
- package/dist/esm/util/helpers.d.ts +1 -2
- package/dist/esm/util/helpers.js.map +1 -1
- package/dist/react-native/auth/credentials.d.ts +77 -0
- package/dist/react-native/auth/credentials.js +27 -0
- package/dist/react-native/auth/credentials.js.map +1 -0
- package/dist/react-native/auth/oauth2Flows.d.ts +57 -0
- package/dist/react-native/auth/oauth2Flows.js +4 -0
- package/dist/react-native/auth/oauth2Flows.js.map +1 -0
- package/dist/react-native/auth/schemes.d.ts +53 -0
- package/dist/react-native/auth/schemes.js +4 -0
- package/dist/react-native/auth/schemes.js.map +1 -0
- package/dist/react-native/client/clientHelpers.d.ts +1 -20
- package/dist/react-native/client/clientHelpers.js +21 -30
- package/dist/react-native/client/clientHelpers.js.map +1 -1
- package/dist/react-native/client/common.d.ts +13 -15
- package/dist/react-native/client/common.js.map +1 -1
- package/dist/react-native/client/getClient.d.ts +1 -9
- package/dist/react-native/client/getClient.js +8 -16
- package/dist/react-native/client/getClient.js.map +1 -1
- package/dist/react-native/constants.js +1 -1
- package/dist/react-native/constants.js.map +1 -1
- package/dist/react-native/index.d.ts +3 -3
- package/dist/react-native/index.js +2 -2
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/interfaces.d.ts +10 -2
- package/dist/react-native/interfaces.js.map +1 -1
- package/dist/react-native/pipelineRequest.d.ts +1 -2
- package/dist/react-native/pipelineRequest.js.map +1 -1
- package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
- package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.js +31 -0
- package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
- package/dist/react-native/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
- package/dist/react-native/policies/auth/basicAuthenticationPolicy.js +31 -0
- package/dist/react-native/policies/auth/basicAuthenticationPolicy.js.map +1 -0
- package/dist/react-native/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
- package/dist/react-native/policies/auth/bearerAuthenticationPolicy.js +31 -0
- package/dist/react-native/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
- package/dist/react-native/policies/auth/checkInsecureConnection.d.ts +9 -0
- package/dist/react-native/policies/auth/checkInsecureConnection.js +50 -0
- package/dist/react-native/policies/auth/checkInsecureConnection.js.map +1 -0
- package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
- package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.js +31 -0
- package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
- package/dist/react-native/util/aborterUtils.d.ts +3 -4
- package/dist/react-native/util/aborterUtils.js.map +1 -1
- package/dist/react-native/util/helpers.d.ts +1 -2
- package/dist/react-native/util/helpers.js.map +1 -1
- package/package.json +1 -1
- package/dist/browser/abort-controller/AbortSignalLike.d.ts +0 -19
- package/dist/browser/abort-controller/AbortSignalLike.js.map +0 -1
- package/dist/browser/accessTokenCache.d.ts +0 -40
- package/dist/browser/accessTokenCache.js +0 -32
- package/dist/browser/accessTokenCache.js.map +0 -1
- package/dist/browser/auth/keyCredential.d.ts +0 -16
- package/dist/browser/auth/keyCredential.js +0 -12
- package/dist/browser/auth/keyCredential.js.map +0 -1
- package/dist/browser/auth/tokenCredential.d.ts +0 -71
- package/dist/browser/auth/tokenCredential.js +0 -19
- package/dist/browser/auth/tokenCredential.js.map +0 -1
- package/dist/browser/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
- package/dist/browser/client/keyCredentialAuthenticationPolicy.js +0 -16
- package/dist/browser/client/keyCredentialAuthenticationPolicy.js.map +0 -1
- package/dist/browser/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
- package/dist/browser/policies/bearerTokenAuthenticationPolicy.js +0 -107
- package/dist/browser/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
- package/dist/browser/util/tokenCycler.d.ts +0 -45
- package/dist/browser/util/tokenCycler.js +0 -162
- package/dist/browser/util/tokenCycler.js.map +0 -1
- package/dist/commonjs/abort-controller/AbortSignalLike.d.ts +0 -19
- package/dist/commonjs/abort-controller/AbortSignalLike.js.map +0 -1
- package/dist/commonjs/accessTokenCache.d.ts +0 -40
- package/dist/commonjs/accessTokenCache.js +0 -36
- package/dist/commonjs/accessTokenCache.js.map +0 -1
- package/dist/commonjs/auth/keyCredential.d.ts +0 -16
- package/dist/commonjs/auth/keyCredential.js +0 -15
- package/dist/commonjs/auth/keyCredential.js.map +0 -1
- package/dist/commonjs/auth/tokenCredential.d.ts +0 -71
- package/dist/commonjs/auth/tokenCredential.js +0 -22
- package/dist/commonjs/auth/tokenCredential.js.map +0 -1
- package/dist/commonjs/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
- package/dist/commonjs/client/keyCredentialAuthenticationPolicy.js +0 -20
- package/dist/commonjs/client/keyCredentialAuthenticationPolicy.js.map +0 -1
- package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
- package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.js +0 -111
- package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
- package/dist/commonjs/util/tokenCycler.d.ts +0 -45
- package/dist/commonjs/util/tokenCycler.js +0 -166
- package/dist/commonjs/util/tokenCycler.js.map +0 -1
- package/dist/esm/abort-controller/AbortSignalLike.d.ts +0 -19
- package/dist/esm/abort-controller/AbortSignalLike.js.map +0 -1
- package/dist/esm/accessTokenCache.d.ts +0 -40
- package/dist/esm/accessTokenCache.js +0 -32
- package/dist/esm/accessTokenCache.js.map +0 -1
- package/dist/esm/auth/keyCredential.d.ts +0 -16
- package/dist/esm/auth/keyCredential.js +0 -12
- package/dist/esm/auth/keyCredential.js.map +0 -1
- package/dist/esm/auth/tokenCredential.d.ts +0 -71
- package/dist/esm/auth/tokenCredential.js +0 -19
- package/dist/esm/auth/tokenCredential.js.map +0 -1
- package/dist/esm/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
- package/dist/esm/client/keyCredentialAuthenticationPolicy.js +0 -16
- package/dist/esm/client/keyCredentialAuthenticationPolicy.js.map +0 -1
- package/dist/esm/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
- package/dist/esm/policies/bearerTokenAuthenticationPolicy.js +0 -107
- package/dist/esm/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
- package/dist/esm/util/tokenCycler.d.ts +0 -45
- package/dist/esm/util/tokenCycler.js +0 -162
- package/dist/esm/util/tokenCycler.js.map +0 -1
- package/dist/react-native/abort-controller/AbortSignalLike.d.ts +0 -19
- package/dist/react-native/abort-controller/AbortSignalLike.js.map +0 -1
- package/dist/react-native/accessTokenCache.d.ts +0 -40
- package/dist/react-native/accessTokenCache.js +0 -32
- package/dist/react-native/accessTokenCache.js.map +0 -1
- package/dist/react-native/auth/keyCredential.d.ts +0 -16
- package/dist/react-native/auth/keyCredential.js +0 -12
- package/dist/react-native/auth/keyCredential.js.map +0 -1
- package/dist/react-native/auth/tokenCredential.d.ts +0 -71
- package/dist/react-native/auth/tokenCredential.js +0 -19
- package/dist/react-native/auth/tokenCredential.js.map +0 -1
- package/dist/react-native/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
- package/dist/react-native/client/keyCredentialAuthenticationPolicy.js +0 -16
- package/dist/react-native/client/keyCredentialAuthenticationPolicy.js.map +0 -1
- package/dist/react-native/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
- package/dist/react-native/policies/bearerTokenAuthenticationPolicy.js +0 -107
- package/dist/react-native/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
- package/dist/react-native/util/tokenCycler.d.ts +0 -45
- package/dist/react-native/util/tokenCycler.js +0 -162
- package/dist/react-native/util/tokenCycler.js.map +0 -1
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { AbortSignalLike } from "../abort-controller/AbortSignalLike.js";
|
|
2
|
-
/**
|
|
3
|
-
* Represents a credential capable of providing an authentication token.
|
|
4
|
-
*/
|
|
5
|
-
export interface TokenCredential {
|
|
6
|
-
/**
|
|
7
|
-
* Gets the token provided by this credential.
|
|
8
|
-
*
|
|
9
|
-
* This method is called automatically by Azure SDK client libraries. You may call this method
|
|
10
|
-
* directly, but you must also handle token caching and token refreshing.
|
|
11
|
-
*
|
|
12
|
-
* @param scopes - The list of scopes for which the token will have access.
|
|
13
|
-
* @param options - The options used to configure any requests this
|
|
14
|
-
* TokenCredential implementation might make.
|
|
15
|
-
*/
|
|
16
|
-
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Defines options for TokenCredential.getToken.
|
|
20
|
-
*/
|
|
21
|
-
export interface GetTokenOptions {
|
|
22
|
-
/**
|
|
23
|
-
* The signal which can be used to abort requests.
|
|
24
|
-
*/
|
|
25
|
-
abortSignal?: AbortSignalLike;
|
|
26
|
-
/**
|
|
27
|
-
* Options used when creating and sending HTTP requests for this operation.
|
|
28
|
-
*/
|
|
29
|
-
requestOptions?: {
|
|
30
|
-
/**
|
|
31
|
-
* The number of milliseconds a request can take before automatically being terminated.
|
|
32
|
-
*/
|
|
33
|
-
timeout?: number;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Claim details to perform the Continuous Access Evaluation authentication flow
|
|
37
|
-
*/
|
|
38
|
-
claims?: string;
|
|
39
|
-
/**
|
|
40
|
-
* Indicates whether to enable the Continuous Access Evaluation authentication flow
|
|
41
|
-
*/
|
|
42
|
-
enableCae?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Allows specifying a tenantId. Useful to handle challenges that provide tenant Id hints.
|
|
45
|
-
*/
|
|
46
|
-
tenantId?: string;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Represents an access token with an expiration time.
|
|
50
|
-
*/
|
|
51
|
-
export interface AccessToken {
|
|
52
|
-
/**
|
|
53
|
-
* The access token returned by the authentication service.
|
|
54
|
-
*/
|
|
55
|
-
token: string;
|
|
56
|
-
/**
|
|
57
|
-
* The access token's expiration timestamp in milliseconds, UNIX epoch time.
|
|
58
|
-
*/
|
|
59
|
-
expiresOnTimestamp: number;
|
|
60
|
-
/**
|
|
61
|
-
* The timestamp when the access token should be refreshed, in milliseconds, UNIX epoch time.
|
|
62
|
-
*/
|
|
63
|
-
refreshAfterTimestamp?: number;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Tests an object to determine whether it implements TokenCredential.
|
|
67
|
-
*
|
|
68
|
-
* @param credential - The assumed TokenCredential to be tested.
|
|
69
|
-
*/
|
|
70
|
-
export declare function isTokenCredential(credential: unknown): credential is TokenCredential;
|
|
71
|
-
//# sourceMappingURL=tokenCredential.d.ts.map
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT License.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.isTokenCredential = isTokenCredential;
|
|
6
|
-
/**
|
|
7
|
-
* Tests an object to determine whether it implements TokenCredential.
|
|
8
|
-
*
|
|
9
|
-
* @param credential - The assumed TokenCredential to be tested.
|
|
10
|
-
*/
|
|
11
|
-
function isTokenCredential(credential) {
|
|
12
|
-
// Check for an object with a 'getToken' function and possibly with
|
|
13
|
-
// a 'signRequest' function. We do this check to make sure that
|
|
14
|
-
// a ServiceClientCredentials implementor (like TokenClientCredentials
|
|
15
|
-
// in ms-rest-nodeauth) doesn't get mistaken for a TokenCredential if
|
|
16
|
-
// it doesn't actually implement TokenCredential also.
|
|
17
|
-
const castCredential = credential;
|
|
18
|
-
return (castCredential &&
|
|
19
|
-
typeof castCredential.getToken === "function" &&
|
|
20
|
-
(castCredential.signRequest === undefined || castCredential.getToken.length > 0));
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=tokenCredential.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokenCredential.js","sourceRoot":"","sources":["../../../src/auth/tokenCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA+ElC,8CAeC;AApBD;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,UAAmB;IACnD,mEAAmE;IACnE,gEAAgE;IAChE,sEAAsE;IACtE,qEAAqE;IACrE,sDAAsD;IACtD,MAAM,cAAc,GAAG,UAGtB,CAAC;IACF,OAAO,CACL,cAAc;QACd,OAAO,cAAc,CAAC,QAAQ,KAAK,UAAU;QAC7C,CAAC,cAAc,CAAC,WAAW,KAAK,SAAS,IAAI,cAAc,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CACjF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\n\n/**\n * Represents a credential capable of providing an authentication token.\n */\nexport interface TokenCredential {\n /**\n * Gets the token provided by this credential.\n *\n * This method is called automatically by Azure SDK client libraries. You may call this method\n * directly, but you must also handle token caching and token refreshing.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;\n}\n\n/**\n * Defines options for TokenCredential.getToken.\n */\nexport interface GetTokenOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: {\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n };\n /**\n * Claim details to perform the Continuous Access Evaluation authentication flow\n */\n claims?: string;\n /**\n * Indicates whether to enable the Continuous Access Evaluation authentication flow\n */\n enableCae?: boolean;\n /**\n * Allows specifying a tenantId. Useful to handle challenges that provide tenant Id hints.\n */\n tenantId?: string;\n}\n\n/**\n * Represents an access token with an expiration time.\n */\nexport interface AccessToken {\n /**\n * The access token returned by the authentication service.\n */\n token: string;\n\n /**\n * The access token's expiration timestamp in milliseconds, UNIX epoch time.\n */\n expiresOnTimestamp: number;\n\n /**\n * The timestamp when the access token should be refreshed, in milliseconds, UNIX epoch time.\n */\n refreshAfterTimestamp?: number;\n\n // UNBRANDED DIFFERENCE: Unbranded Core does not support PoP (\"Proof-of-Presence\") tokens.\n}\n\n/**\n * Tests an object to determine whether it implements TokenCredential.\n *\n * @param credential - The assumed TokenCredential to be tested.\n */\nexport function isTokenCredential(credential: unknown): credential is TokenCredential {\n // Check for an object with a 'getToken' function and possibly with\n // a 'signRequest' function. We do this check to make sure that\n // a ServiceClientCredentials implementor (like TokenClientCredentials\n // in ms-rest-nodeauth) doesn't get mistaken for a TokenCredential if\n // it doesn't actually implement TokenCredential also.\n const castCredential = credential as {\n getToken: unknown;\n signRequest: unknown;\n };\n return (\n castCredential &&\n typeof castCredential.getToken === \"function\" &&\n (castCredential.signRequest === undefined || castCredential.getToken.length > 0)\n );\n}\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { KeyCredential } from "../auth/keyCredential.js";
|
|
2
|
-
import type { PipelinePolicy } from "../pipeline.js";
|
|
3
|
-
/**
|
|
4
|
-
* The programmatic identifier of the bearerTokenAuthenticationPolicy.
|
|
5
|
-
*/
|
|
6
|
-
export declare const keyCredentialAuthenticationPolicyName = "keyCredentialAuthenticationPolicy";
|
|
7
|
-
export declare function keyCredentialAuthenticationPolicy(credential: KeyCredential, apiKeyHeaderName: string): PipelinePolicy;
|
|
8
|
-
//# sourceMappingURL=keyCredentialAuthenticationPolicy.d.ts.map
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT License.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.keyCredentialAuthenticationPolicyName = void 0;
|
|
6
|
-
exports.keyCredentialAuthenticationPolicy = keyCredentialAuthenticationPolicy;
|
|
7
|
-
/**
|
|
8
|
-
* The programmatic identifier of the bearerTokenAuthenticationPolicy.
|
|
9
|
-
*/
|
|
10
|
-
exports.keyCredentialAuthenticationPolicyName = "keyCredentialAuthenticationPolicy";
|
|
11
|
-
function keyCredentialAuthenticationPolicy(credential, apiKeyHeaderName) {
|
|
12
|
-
return {
|
|
13
|
-
name: exports.keyCredentialAuthenticationPolicyName,
|
|
14
|
-
async sendRequest(request, next) {
|
|
15
|
-
request.headers.set(apiKeyHeaderName, credential.key);
|
|
16
|
-
return next(request);
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=keyCredentialAuthenticationPolicy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyCredentialAuthenticationPolicy.js","sourceRoot":"","sources":["../../../src/client/keyCredentialAuthenticationPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAWlC,8EAWC;AAhBD;;GAEG;AACU,QAAA,qCAAqC,GAAG,mCAAmC,CAAC;AAEzF,SAAgB,iCAAiC,CAC/C,UAAyB,EACzB,gBAAwB;IAExB,OAAO;QACL,IAAI,EAAE,6CAAqC;QAC3C,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;YACtD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { KeyCredential } from \"../auth/keyCredential.js\";\nimport type { PipelineRequest, PipelineResponse, SendRequest } from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\n\n/**\n * The programmatic identifier of the bearerTokenAuthenticationPolicy.\n */\nexport const keyCredentialAuthenticationPolicyName = \"keyCredentialAuthenticationPolicy\";\n\nexport function keyCredentialAuthenticationPolicy(\n credential: KeyCredential,\n apiKeyHeaderName: string,\n): PipelinePolicy {\n return {\n name: keyCredentialAuthenticationPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.headers.set(apiKeyHeaderName, credential.key);\n return next(request);\n },\n };\n}\n"]}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type { AccessToken, GetTokenOptions, TokenCredential } from "../auth/tokenCredential.js";
|
|
2
|
-
import type { TypeSpecRuntimeLogger } from "../logger/logger.js";
|
|
3
|
-
import type { PipelineRequest, PipelineResponse } from "../interfaces.js";
|
|
4
|
-
import type { PipelinePolicy } from "../pipeline.js";
|
|
5
|
-
/**
|
|
6
|
-
* The programmatic identifier of the bearerTokenAuthenticationPolicy.
|
|
7
|
-
*/
|
|
8
|
-
export declare const bearerTokenAuthenticationPolicyName = "bearerTokenAuthenticationPolicy";
|
|
9
|
-
/**
|
|
10
|
-
* Options sent to the authorizeRequest callback
|
|
11
|
-
*/
|
|
12
|
-
export interface AuthorizeRequestOptions {
|
|
13
|
-
/**
|
|
14
|
-
* The scopes for which the bearer token applies.
|
|
15
|
-
*/
|
|
16
|
-
scopes: string[];
|
|
17
|
-
/**
|
|
18
|
-
* Function that retrieves either a cached access token or a new access token.
|
|
19
|
-
*/
|
|
20
|
-
getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;
|
|
21
|
-
/**
|
|
22
|
-
* Request that the policy is trying to fulfill.
|
|
23
|
-
*/
|
|
24
|
-
request: PipelineRequest;
|
|
25
|
-
/**
|
|
26
|
-
* A logger, if one was sent through the HTTP pipeline.
|
|
27
|
-
*/
|
|
28
|
-
logger?: TypeSpecRuntimeLogger;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Options sent to the authorizeRequestOnChallenge callback
|
|
32
|
-
*/
|
|
33
|
-
export interface AuthorizeRequestOnChallengeOptions {
|
|
34
|
-
/**
|
|
35
|
-
* The scopes for which the bearer token applies.
|
|
36
|
-
*/
|
|
37
|
-
scopes: string[];
|
|
38
|
-
/**
|
|
39
|
-
* Function that retrieves either a cached access token or a new access token.
|
|
40
|
-
*/
|
|
41
|
-
getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;
|
|
42
|
-
/**
|
|
43
|
-
* Request that the policy is trying to fulfill.
|
|
44
|
-
*/
|
|
45
|
-
request: PipelineRequest;
|
|
46
|
-
/**
|
|
47
|
-
* Response containing the challenge.
|
|
48
|
-
*/
|
|
49
|
-
response: PipelineResponse;
|
|
50
|
-
/**
|
|
51
|
-
* A logger, if one was sent through the HTTP pipeline.
|
|
52
|
-
*/
|
|
53
|
-
logger?: TypeSpecRuntimeLogger;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Options to override the processing of [Continuous Access Evaluation](https://learn.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.
|
|
57
|
-
*/
|
|
58
|
-
export interface ChallengeCallbacks {
|
|
59
|
-
/**
|
|
60
|
-
* Allows for the authorization of the main request of this policy before it's sent.
|
|
61
|
-
*/
|
|
62
|
-
authorizeRequest?(options: AuthorizeRequestOptions): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Allows to handle authentication challenges and to re-authorize the request.
|
|
65
|
-
* The response containing the challenge is `options.response`.
|
|
66
|
-
* If this method returns true, the underlying request will be sent once again.
|
|
67
|
-
* The request may be modified before being sent.
|
|
68
|
-
*/
|
|
69
|
-
authorizeRequestOnChallenge?(options: AuthorizeRequestOnChallengeOptions): Promise<boolean>;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Options to configure the bearerTokenAuthenticationPolicy
|
|
73
|
-
*/
|
|
74
|
-
export interface BearerTokenAuthenticationPolicyOptions {
|
|
75
|
-
/**
|
|
76
|
-
* The TokenCredential implementation that can supply the bearer token.
|
|
77
|
-
*/
|
|
78
|
-
credential?: TokenCredential;
|
|
79
|
-
/**
|
|
80
|
-
* The scopes for which the bearer token applies.
|
|
81
|
-
*/
|
|
82
|
-
scopes: string | string[];
|
|
83
|
-
/**
|
|
84
|
-
* Allows for the processing of [Continuous Access Evaluation](https://learn.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.
|
|
85
|
-
* If provided, it must contain at least the `authorizeRequestOnChallenge` method.
|
|
86
|
-
* If provided, after a request is sent, if it has a challenge, it can be processed to re-send the original request with the relevant challenge information.
|
|
87
|
-
*/
|
|
88
|
-
challengeCallbacks?: ChallengeCallbacks;
|
|
89
|
-
/**
|
|
90
|
-
* A logger can be sent for debugging purposes.
|
|
91
|
-
*/
|
|
92
|
-
logger?: TypeSpecRuntimeLogger;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* A policy that can request a token from a TokenCredential implementation and
|
|
96
|
-
* then apply it to the Authorization header of a request as a Bearer token.
|
|
97
|
-
*/
|
|
98
|
-
export declare function bearerTokenAuthenticationPolicy(options: BearerTokenAuthenticationPolicyOptions): PipelinePolicy;
|
|
99
|
-
//# sourceMappingURL=bearerTokenAuthenticationPolicy.d.ts.map
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT License.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.bearerTokenAuthenticationPolicyName = void 0;
|
|
6
|
-
exports.bearerTokenAuthenticationPolicy = bearerTokenAuthenticationPolicy;
|
|
7
|
-
const tokenCycler_js_1 = require("../util/tokenCycler.js");
|
|
8
|
-
const log_js_1 = require("../log.js");
|
|
9
|
-
/**
|
|
10
|
-
* The programmatic identifier of the bearerTokenAuthenticationPolicy.
|
|
11
|
-
*/
|
|
12
|
-
exports.bearerTokenAuthenticationPolicyName = "bearerTokenAuthenticationPolicy";
|
|
13
|
-
/**
|
|
14
|
-
* Default authorize request handler
|
|
15
|
-
*/
|
|
16
|
-
async function defaultAuthorizeRequest(options) {
|
|
17
|
-
const { scopes, getAccessToken, request } = options;
|
|
18
|
-
const getTokenOptions = {
|
|
19
|
-
abortSignal: request.abortSignal,
|
|
20
|
-
};
|
|
21
|
-
const accessToken = await getAccessToken(scopes, getTokenOptions);
|
|
22
|
-
if (accessToken) {
|
|
23
|
-
options.request.headers.set("Authorization", `Bearer ${accessToken.token}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* We will retrieve the challenge only if the response status code was 401,
|
|
28
|
-
* and if the response contained the header "WWW-Authenticate" with a non-empty value.
|
|
29
|
-
*/
|
|
30
|
-
function getChallenge(response) {
|
|
31
|
-
const challenge = response.headers.get("WWW-Authenticate");
|
|
32
|
-
if (response.status === 401 && challenge) {
|
|
33
|
-
return challenge;
|
|
34
|
-
}
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* A policy that can request a token from a TokenCredential implementation and
|
|
39
|
-
* then apply it to the Authorization header of a request as a Bearer token.
|
|
40
|
-
*/
|
|
41
|
-
function bearerTokenAuthenticationPolicy(options) {
|
|
42
|
-
var _a;
|
|
43
|
-
const { credential, scopes, challengeCallbacks } = options;
|
|
44
|
-
const logger = options.logger || log_js_1.logger;
|
|
45
|
-
const callbacks = Object.assign({ authorizeRequest: (_a = challengeCallbacks === null || challengeCallbacks === void 0 ? void 0 : challengeCallbacks.authorizeRequest) !== null && _a !== void 0 ? _a : defaultAuthorizeRequest, authorizeRequestOnChallenge: challengeCallbacks === null || challengeCallbacks === void 0 ? void 0 : challengeCallbacks.authorizeRequestOnChallenge }, challengeCallbacks);
|
|
46
|
-
// This function encapsulates the entire process of reliably retrieving the token
|
|
47
|
-
// The options are left out of the public API until there's demand to configure this.
|
|
48
|
-
// Remember to extend `BearerTokenAuthenticationPolicyOptions` with `TokenCyclerOptions`
|
|
49
|
-
// in order to pass through the `options` object.
|
|
50
|
-
const getAccessToken = credential
|
|
51
|
-
? (0, tokenCycler_js_1.createTokenCycler)(credential /* , options */)
|
|
52
|
-
: () => Promise.resolve(null);
|
|
53
|
-
return {
|
|
54
|
-
name: exports.bearerTokenAuthenticationPolicyName,
|
|
55
|
-
/**
|
|
56
|
-
* If there's no challenge parameter:
|
|
57
|
-
* - It will try to retrieve the token using the cache, or the credential's getToken.
|
|
58
|
-
* - Then it will try the next policy with or without the retrieved token.
|
|
59
|
-
*
|
|
60
|
-
* It uses the challenge parameters to:
|
|
61
|
-
* - Skip a first attempt to get the token from the credential if there's no cached token,
|
|
62
|
-
* since it expects the token to be retrievable only after the challenge.
|
|
63
|
-
* - Prepare the outgoing request if the `prepareRequest` method has been provided.
|
|
64
|
-
* - Send an initial request to receive the challenge if it fails.
|
|
65
|
-
* - Process a challenge if the response contains it.
|
|
66
|
-
* - Retrieve a token with the challenge information, then re-send the request.
|
|
67
|
-
*/
|
|
68
|
-
async sendRequest(request, next) {
|
|
69
|
-
if (!request.url.toLowerCase().startsWith("https://")) {
|
|
70
|
-
throw new Error("Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.");
|
|
71
|
-
}
|
|
72
|
-
await callbacks.authorizeRequest({
|
|
73
|
-
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
74
|
-
request,
|
|
75
|
-
getAccessToken,
|
|
76
|
-
logger,
|
|
77
|
-
});
|
|
78
|
-
let response;
|
|
79
|
-
let error;
|
|
80
|
-
try {
|
|
81
|
-
response = await next(request);
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
error = err;
|
|
85
|
-
response = err.response;
|
|
86
|
-
}
|
|
87
|
-
if (callbacks.authorizeRequestOnChallenge &&
|
|
88
|
-
(response === null || response === void 0 ? void 0 : response.status) === 401 &&
|
|
89
|
-
getChallenge(response)) {
|
|
90
|
-
// processes challenge
|
|
91
|
-
const shouldSendRequest = await callbacks.authorizeRequestOnChallenge({
|
|
92
|
-
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
93
|
-
request,
|
|
94
|
-
response,
|
|
95
|
-
getAccessToken,
|
|
96
|
-
logger,
|
|
97
|
-
});
|
|
98
|
-
if (shouldSendRequest) {
|
|
99
|
-
return next(request);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (error) {
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
return response;
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=bearerTokenAuthenticationPolicy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bearerTokenAuthenticationPolicy.js","sourceRoot":"","sources":["../../../src/policies/bearerTokenAuthenticationPolicy.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"../auth/tokenCredential.js\";\nimport type { TypeSpecRuntimeLogger } from \"../logger/logger.js\";\nimport type { PipelineRequest, PipelineResponse, SendRequest } from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { createTokenCycler } from \"../util/tokenCycler.js\";\nimport { logger as coreLogger } from \"../log.js\";\n\n/**\n * The programmatic identifier of the bearerTokenAuthenticationPolicy.\n */\nexport const bearerTokenAuthenticationPolicyName = \"bearerTokenAuthenticationPolicy\";\n\n/**\n * Options sent to the authorizeRequest callback\n */\nexport interface AuthorizeRequestOptions {\n /**\n * The scopes for which the bearer token applies.\n */\n scopes: string[];\n /**\n * Function that retrieves either a cached access token or a new access token.\n */\n getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;\n /**\n * Request that the policy is trying to fulfill.\n */\n request: PipelineRequest;\n /**\n * A logger, if one was sent through the HTTP pipeline.\n */\n logger?: TypeSpecRuntimeLogger;\n}\n\n/**\n * Options sent to the authorizeRequestOnChallenge callback\n */\nexport interface AuthorizeRequestOnChallengeOptions {\n /**\n * The scopes for which the bearer token applies.\n */\n scopes: string[];\n /**\n * Function that retrieves either a cached access token or a new access token.\n */\n getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;\n /**\n * Request that the policy is trying to fulfill.\n */\n request: PipelineRequest;\n /**\n * Response containing the challenge.\n */\n response: PipelineResponse;\n /**\n * A logger, if one was sent through the HTTP pipeline.\n */\n logger?: TypeSpecRuntimeLogger;\n}\n\n/**\n * Options to override the processing of [Continuous Access Evaluation](https://learn.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.\n */\nexport interface ChallengeCallbacks {\n /**\n * Allows for the authorization of the main request of this policy before it's sent.\n */\n authorizeRequest?(options: AuthorizeRequestOptions): Promise<void>;\n /**\n * Allows to handle authentication challenges and to re-authorize the request.\n * The response containing the challenge is `options.response`.\n * If this method returns true, the underlying request will be sent once again.\n * The request may be modified before being sent.\n */\n authorizeRequestOnChallenge?(options: AuthorizeRequestOnChallengeOptions): Promise<boolean>;\n}\n\n/**\n * Options to configure the bearerTokenAuthenticationPolicy\n */\nexport interface BearerTokenAuthenticationPolicyOptions {\n /**\n * The TokenCredential implementation that can supply the bearer token.\n */\n credential?: TokenCredential;\n /**\n * The scopes for which the bearer token applies.\n */\n scopes: string | string[];\n /**\n * Allows for the processing of [Continuous Access Evaluation](https://learn.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.\n * If provided, it must contain at least the `authorizeRequestOnChallenge` method.\n * If provided, after a request is sent, if it has a challenge, it can be processed to re-send the original request with the relevant challenge information.\n */\n challengeCallbacks?: ChallengeCallbacks;\n /**\n * A logger can be sent for debugging purposes.\n */\n logger?: TypeSpecRuntimeLogger;\n}\n\n/**\n * Default authorize request handler\n */\nasync function defaultAuthorizeRequest(options: AuthorizeRequestOptions): Promise<void> {\n const { scopes, getAccessToken, request } = options;\n const getTokenOptions: GetTokenOptions = {\n abortSignal: request.abortSignal,\n };\n const accessToken = await getAccessToken(scopes, getTokenOptions);\n\n if (accessToken) {\n options.request.headers.set(\"Authorization\", `Bearer ${accessToken.token}`);\n }\n}\n\n/**\n * We will retrieve the challenge only if the response status code was 401,\n * and if the response contained the header \"WWW-Authenticate\" with a non-empty value.\n */\nfunction getChallenge(response: PipelineResponse): string | undefined {\n const challenge = response.headers.get(\"WWW-Authenticate\");\n if (response.status === 401 && challenge) {\n return challenge;\n }\n return;\n}\n\n/**\n * A policy that can request a token from a TokenCredential implementation and\n * then apply it to the Authorization header of a request as a Bearer token.\n */\nexport function bearerTokenAuthenticationPolicy(\n options: BearerTokenAuthenticationPolicyOptions,\n): PipelinePolicy {\n const { credential, scopes, challengeCallbacks } = options;\n const logger = options.logger || coreLogger;\n const callbacks = {\n authorizeRequest: challengeCallbacks?.authorizeRequest ?? defaultAuthorizeRequest,\n authorizeRequestOnChallenge: challengeCallbacks?.authorizeRequestOnChallenge,\n // keep all other properties\n ...challengeCallbacks,\n };\n\n // This function encapsulates the entire process of reliably retrieving the token\n // The options are left out of the public API until there's demand to configure this.\n // Remember to extend `BearerTokenAuthenticationPolicyOptions` with `TokenCyclerOptions`\n // in order to pass through the `options` object.\n const getAccessToken = credential\n ? createTokenCycler(credential /* , options */)\n : () => Promise.resolve(null);\n\n return {\n name: bearerTokenAuthenticationPolicyName,\n /**\n * If there's no challenge parameter:\n * - It will try to retrieve the token using the cache, or the credential's getToken.\n * - Then it will try the next policy with or without the retrieved token.\n *\n * It uses the challenge parameters to:\n * - Skip a first attempt to get the token from the credential if there's no cached token,\n * since it expects the token to be retrievable only after the challenge.\n * - Prepare the outgoing request if the `prepareRequest` method has been provided.\n * - Send an initial request to receive the challenge if it fails.\n * - Process a challenge if the response contains it.\n * - Retrieve a token with the challenge information, then re-send the request.\n */\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (!request.url.toLowerCase().startsWith(\"https://\")) {\n throw new Error(\n \"Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.\",\n );\n }\n\n await callbacks.authorizeRequest({\n scopes: Array.isArray(scopes) ? scopes : [scopes],\n request,\n getAccessToken,\n logger,\n });\n\n let response: PipelineResponse;\n let error: Error | undefined;\n try {\n response = await next(request);\n } catch (err: any) {\n error = err;\n response = err.response;\n }\n\n if (\n callbacks.authorizeRequestOnChallenge &&\n response?.status === 401 &&\n getChallenge(response)\n ) {\n // processes challenge\n const shouldSendRequest = await callbacks.authorizeRequestOnChallenge({\n scopes: Array.isArray(scopes) ? scopes : [scopes],\n request,\n response,\n getAccessToken,\n logger,\n });\n\n if (shouldSendRequest) {\n return next(request);\n }\n }\n\n if (error) {\n throw error;\n } else {\n return response;\n }\n },\n };\n}\n"]}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { AccessToken, GetTokenOptions, TokenCredential } from "../auth/tokenCredential.js";
|
|
2
|
-
/**
|
|
3
|
-
* A function that gets a promise of an access token and allows providing
|
|
4
|
-
* options.
|
|
5
|
-
*
|
|
6
|
-
* @param options - the options to pass to the underlying token provider
|
|
7
|
-
*/
|
|
8
|
-
export type AccessTokenGetter = (scopes: string | string[], options: GetTokenOptions) => Promise<AccessToken>;
|
|
9
|
-
export interface TokenCyclerOptions {
|
|
10
|
-
/**
|
|
11
|
-
* The window of time before token expiration during which the token will be
|
|
12
|
-
* considered unusable due to risk of the token expiring before sending the
|
|
13
|
-
* request.
|
|
14
|
-
*
|
|
15
|
-
* This will only become meaningful if the refresh fails for over
|
|
16
|
-
* (refreshWindow - forcedRefreshWindow) milliseconds.
|
|
17
|
-
*/
|
|
18
|
-
forcedRefreshWindowInMs: number;
|
|
19
|
-
/**
|
|
20
|
-
* Interval in milliseconds to retry failed token refreshes.
|
|
21
|
-
*/
|
|
22
|
-
retryIntervalInMs: number;
|
|
23
|
-
/**
|
|
24
|
-
* The window of time before token expiration during which
|
|
25
|
-
* we will attempt to refresh the token.
|
|
26
|
-
*/
|
|
27
|
-
refreshWindowInMs: number;
|
|
28
|
-
}
|
|
29
|
-
export declare const DEFAULT_CYCLER_OPTIONS: TokenCyclerOptions;
|
|
30
|
-
/**
|
|
31
|
-
* Creates a token cycler from a credential, scopes, and optional settings.
|
|
32
|
-
*
|
|
33
|
-
* A token cycler represents a way to reliably retrieve a valid access token
|
|
34
|
-
* from a TokenCredential. It will handle initializing the token, refreshing it
|
|
35
|
-
* when it nears expiration, and synchronizes refresh attempts to avoid
|
|
36
|
-
* concurrency hazards.
|
|
37
|
-
*
|
|
38
|
-
* @param credential - the underlying TokenCredential that provides the access
|
|
39
|
-
* token
|
|
40
|
-
* @param tokenCyclerOptions - optionally override default settings for the cycler
|
|
41
|
-
*
|
|
42
|
-
* @returns - a function that reliably produces a valid access token
|
|
43
|
-
*/
|
|
44
|
-
export declare function createTokenCycler(credential: TokenCredential, tokenCyclerOptions?: Partial<TokenCyclerOptions>): AccessTokenGetter;
|
|
45
|
-
//# sourceMappingURL=tokenCycler.d.ts.map
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT License.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.DEFAULT_CYCLER_OPTIONS = void 0;
|
|
6
|
-
exports.createTokenCycler = createTokenCycler;
|
|
7
|
-
const helpers_js_1 = require("./helpers.js");
|
|
8
|
-
// Default options for the cycler if none are provided
|
|
9
|
-
exports.DEFAULT_CYCLER_OPTIONS = {
|
|
10
|
-
forcedRefreshWindowInMs: 1000, // Force waiting for a refresh 1s before the token expires
|
|
11
|
-
retryIntervalInMs: 3000, // Allow refresh attempts every 3s
|
|
12
|
-
refreshWindowInMs: 1000 * 60 * 2, // Start refreshing 2m before expiry
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Converts an an unreliable access token getter (which may resolve with null)
|
|
16
|
-
* into an AccessTokenGetter by retrying the unreliable getter in a regular
|
|
17
|
-
* interval.
|
|
18
|
-
*
|
|
19
|
-
* @param getAccessToken - A function that produces a promise of an access token that may fail by returning null.
|
|
20
|
-
* @param retryIntervalInMs - The time (in milliseconds) to wait between retry attempts.
|
|
21
|
-
* @param refreshTimeout - The timestamp after which the refresh attempt will fail, throwing an exception.
|
|
22
|
-
* @returns - A promise that, if it resolves, will resolve with an access token.
|
|
23
|
-
*/
|
|
24
|
-
async function beginRefresh(getAccessToken, retryIntervalInMs, refreshTimeout) {
|
|
25
|
-
// This wrapper handles exceptions gracefully as long as we haven't exceeded
|
|
26
|
-
// the timeout.
|
|
27
|
-
async function tryGetAccessToken() {
|
|
28
|
-
if (Date.now() < refreshTimeout) {
|
|
29
|
-
try {
|
|
30
|
-
return await getAccessToken();
|
|
31
|
-
}
|
|
32
|
-
catch (_a) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
const finalToken = await getAccessToken();
|
|
38
|
-
// Timeout is up, so throw if it's still null
|
|
39
|
-
if (finalToken === null) {
|
|
40
|
-
throw new Error("Failed to refresh access token.");
|
|
41
|
-
}
|
|
42
|
-
return finalToken;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
let token = await tryGetAccessToken();
|
|
46
|
-
while (token === null) {
|
|
47
|
-
await (0, helpers_js_1.delay)(retryIntervalInMs);
|
|
48
|
-
token = await tryGetAccessToken();
|
|
49
|
-
}
|
|
50
|
-
return token;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Creates a token cycler from a credential, scopes, and optional settings.
|
|
54
|
-
*
|
|
55
|
-
* A token cycler represents a way to reliably retrieve a valid access token
|
|
56
|
-
* from a TokenCredential. It will handle initializing the token, refreshing it
|
|
57
|
-
* when it nears expiration, and synchronizes refresh attempts to avoid
|
|
58
|
-
* concurrency hazards.
|
|
59
|
-
*
|
|
60
|
-
* @param credential - the underlying TokenCredential that provides the access
|
|
61
|
-
* token
|
|
62
|
-
* @param tokenCyclerOptions - optionally override default settings for the cycler
|
|
63
|
-
*
|
|
64
|
-
* @returns - a function that reliably produces a valid access token
|
|
65
|
-
*/
|
|
66
|
-
function createTokenCycler(credential, tokenCyclerOptions) {
|
|
67
|
-
let refreshWorker = null;
|
|
68
|
-
let token = null;
|
|
69
|
-
let tenantId;
|
|
70
|
-
const options = Object.assign(Object.assign({}, exports.DEFAULT_CYCLER_OPTIONS), tokenCyclerOptions);
|
|
71
|
-
/**
|
|
72
|
-
* This little holder defines several predicates that we use to construct
|
|
73
|
-
* the rules of refreshing the token.
|
|
74
|
-
*/
|
|
75
|
-
const cycler = {
|
|
76
|
-
/**
|
|
77
|
-
* Produces true if a refresh job is currently in progress.
|
|
78
|
-
*/
|
|
79
|
-
get isRefreshing() {
|
|
80
|
-
return refreshWorker !== null;
|
|
81
|
-
},
|
|
82
|
-
/**
|
|
83
|
-
* Produces true if the cycler SHOULD refresh (we are within the refresh
|
|
84
|
-
* window and not already refreshing)
|
|
85
|
-
*/
|
|
86
|
-
get shouldRefresh() {
|
|
87
|
-
var _a;
|
|
88
|
-
if (cycler.isRefreshing) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
if ((token === null || token === void 0 ? void 0 : token.refreshAfterTimestamp) && token.refreshAfterTimestamp < Date.now()) {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
return ((_a = token === null || token === void 0 ? void 0 : token.expiresOnTimestamp) !== null && _a !== void 0 ? _a : 0) - options.refreshWindowInMs < Date.now();
|
|
95
|
-
},
|
|
96
|
-
/**
|
|
97
|
-
* Produces true if the cycler MUST refresh (null or nearly-expired
|
|
98
|
-
* token).
|
|
99
|
-
*/
|
|
100
|
-
get mustRefresh() {
|
|
101
|
-
return (token === null || token.expiresOnTimestamp - options.forcedRefreshWindowInMs < Date.now());
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Starts a refresh job or returns the existing job if one is already
|
|
106
|
-
* running.
|
|
107
|
-
*/
|
|
108
|
-
function refresh(scopes, getTokenOptions) {
|
|
109
|
-
var _a;
|
|
110
|
-
if (!cycler.isRefreshing) {
|
|
111
|
-
// We bind `scopes` here to avoid passing it around a lot
|
|
112
|
-
const tryGetAccessToken = () => credential.getToken(scopes, getTokenOptions);
|
|
113
|
-
// Take advantage of promise chaining to insert an assignment to `token`
|
|
114
|
-
// before the refresh can be considered done.
|
|
115
|
-
refreshWorker = beginRefresh(tryGetAccessToken, options.retryIntervalInMs,
|
|
116
|
-
// If we don't have a token, then we should timeout immediately
|
|
117
|
-
(_a = token === null || token === void 0 ? void 0 : token.expiresOnTimestamp) !== null && _a !== void 0 ? _a : Date.now())
|
|
118
|
-
.then((_token) => {
|
|
119
|
-
refreshWorker = null;
|
|
120
|
-
token = _token;
|
|
121
|
-
tenantId = getTokenOptions.tenantId;
|
|
122
|
-
return token;
|
|
123
|
-
})
|
|
124
|
-
.catch((reason) => {
|
|
125
|
-
// We also should reset the refresher if we enter a failed state. All
|
|
126
|
-
// existing awaiters will throw, but subsequent requests will start a
|
|
127
|
-
// new retry chain.
|
|
128
|
-
refreshWorker = null;
|
|
129
|
-
token = null;
|
|
130
|
-
tenantId = undefined;
|
|
131
|
-
throw reason;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return refreshWorker;
|
|
135
|
-
}
|
|
136
|
-
return async (scopes, tokenOptions) => {
|
|
137
|
-
//
|
|
138
|
-
// Simple rules:
|
|
139
|
-
// - If we MUST refresh, then return the refresh task, blocking
|
|
140
|
-
// the pipeline until a token is available.
|
|
141
|
-
// - If we SHOULD refresh, then run refresh but don't return it
|
|
142
|
-
// (we can still use the cached token).
|
|
143
|
-
// - Return the token, since it's fine if we didn't return in
|
|
144
|
-
// step 1.
|
|
145
|
-
//
|
|
146
|
-
const hasClaimChallenge = Boolean(tokenOptions.claims);
|
|
147
|
-
const tenantIdChanged = tenantId !== tokenOptions.tenantId;
|
|
148
|
-
if (hasClaimChallenge) {
|
|
149
|
-
// If we've received a claim, we know the existing token isn't valid
|
|
150
|
-
// We want to clear it so that that refresh worker won't use the old expiration time as a timeout
|
|
151
|
-
token = null;
|
|
152
|
-
}
|
|
153
|
-
// If the tenantId passed in token options is different to the one we have
|
|
154
|
-
// Or if we are in claim challenge and the token was rejected and a new access token need to be issued, we need to
|
|
155
|
-
// refresh the token with the new tenantId or token.
|
|
156
|
-
const mustRefresh = tenantIdChanged || hasClaimChallenge || cycler.mustRefresh;
|
|
157
|
-
if (mustRefresh) {
|
|
158
|
-
return refresh(scopes, tokenOptions);
|
|
159
|
-
}
|
|
160
|
-
if (cycler.shouldRefresh) {
|
|
161
|
-
refresh(scopes, tokenOptions);
|
|
162
|
-
}
|
|
163
|
-
return token;
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
//# sourceMappingURL=tokenCycler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokenCycler.js","sourceRoot":"","sources":["../../../src/util/tokenCycler.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"../auth/tokenCredential.js\";\nimport { delay } from \"./helpers.js\";\n\n/**\n * A function that gets a promise of an access token and allows providing\n * options.\n *\n * @param options - the options to pass to the underlying token provider\n */\nexport type AccessTokenGetter = (\n scopes: string | string[],\n options: GetTokenOptions,\n) => Promise<AccessToken>;\n\nexport interface TokenCyclerOptions {\n /**\n * The window of time before token expiration during which the token will be\n * considered unusable due to risk of the token expiring before sending the\n * request.\n *\n * This will only become meaningful if the refresh fails for over\n * (refreshWindow - forcedRefreshWindow) milliseconds.\n */\n forcedRefreshWindowInMs: number;\n /**\n * Interval in milliseconds to retry failed token refreshes.\n */\n retryIntervalInMs: number;\n /**\n * The window of time before token expiration during which\n * we will attempt to refresh the token.\n */\n refreshWindowInMs: number;\n}\n\n// Default options for the cycler if none are provided\nexport const DEFAULT_CYCLER_OPTIONS: TokenCyclerOptions = {\n forcedRefreshWindowInMs: 1000, // Force waiting for a refresh 1s before the token expires\n retryIntervalInMs: 3000, // Allow refresh attempts every 3s\n refreshWindowInMs: 1000 * 60 * 2, // Start refreshing 2m before expiry\n};\n\n/**\n * Converts an an unreliable access token getter (which may resolve with null)\n * into an AccessTokenGetter by retrying the unreliable getter in a regular\n * interval.\n *\n * @param getAccessToken - A function that produces a promise of an access token that may fail by returning null.\n * @param retryIntervalInMs - The time (in milliseconds) to wait between retry attempts.\n * @param refreshTimeout - The timestamp after which the refresh attempt will fail, throwing an exception.\n * @returns - A promise that, if it resolves, will resolve with an access token.\n */\nasync function beginRefresh(\n getAccessToken: () => Promise<AccessToken | null>,\n retryIntervalInMs: number,\n refreshTimeout: number,\n): Promise<AccessToken> {\n // This wrapper handles exceptions gracefully as long as we haven't exceeded\n // the timeout.\n async function tryGetAccessToken(): Promise<AccessToken | null> {\n if (Date.now() < refreshTimeout) {\n try {\n return await getAccessToken();\n } catch {\n return null;\n }\n } else {\n const finalToken = await getAccessToken();\n\n // Timeout is up, so throw if it's still null\n if (finalToken === null) {\n throw new Error(\"Failed to refresh access token.\");\n }\n\n return finalToken;\n }\n }\n\n let token: AccessToken | null = await tryGetAccessToken();\n\n while (token === null) {\n await delay(retryIntervalInMs);\n\n token = await tryGetAccessToken();\n }\n\n return token;\n}\n\n/**\n * Creates a token cycler from a credential, scopes, and optional settings.\n *\n * A token cycler represents a way to reliably retrieve a valid access token\n * from a TokenCredential. It will handle initializing the token, refreshing it\n * when it nears expiration, and synchronizes refresh attempts to avoid\n * concurrency hazards.\n *\n * @param credential - the underlying TokenCredential that provides the access\n * token\n * @param tokenCyclerOptions - optionally override default settings for the cycler\n *\n * @returns - a function that reliably produces a valid access token\n */\nexport function createTokenCycler(\n credential: TokenCredential,\n tokenCyclerOptions?: Partial<TokenCyclerOptions>,\n): AccessTokenGetter {\n let refreshWorker: Promise<AccessToken> | null = null;\n let token: AccessToken | null = null;\n let tenantId: string | undefined;\n\n const options = {\n ...DEFAULT_CYCLER_OPTIONS,\n ...tokenCyclerOptions,\n };\n\n /**\n * This little holder defines several predicates that we use to construct\n * the rules of refreshing the token.\n */\n const cycler = {\n /**\n * Produces true if a refresh job is currently in progress.\n */\n get isRefreshing(): boolean {\n return refreshWorker !== null;\n },\n /**\n * Produces true if the cycler SHOULD refresh (we are within the refresh\n * window and not already refreshing)\n */\n get shouldRefresh(): boolean {\n if (cycler.isRefreshing) {\n return false;\n }\n if (token?.refreshAfterTimestamp && token.refreshAfterTimestamp < Date.now()) {\n return true;\n }\n\n return (token?.expiresOnTimestamp ?? 0) - options.refreshWindowInMs < Date.now();\n },\n /**\n * Produces true if the cycler MUST refresh (null or nearly-expired\n * token).\n */\n get mustRefresh(): boolean {\n return (\n token === null || token.expiresOnTimestamp - options.forcedRefreshWindowInMs < Date.now()\n );\n },\n };\n\n /**\n * Starts a refresh job or returns the existing job if one is already\n * running.\n */\n function refresh(\n scopes: string | string[],\n getTokenOptions: GetTokenOptions,\n ): Promise<AccessToken> {\n if (!cycler.isRefreshing) {\n // We bind `scopes` here to avoid passing it around a lot\n const tryGetAccessToken = (): Promise<AccessToken | null> =>\n credential.getToken(scopes, getTokenOptions);\n\n // Take advantage of promise chaining to insert an assignment to `token`\n // before the refresh can be considered done.\n refreshWorker = beginRefresh(\n tryGetAccessToken,\n options.retryIntervalInMs,\n // If we don't have a token, then we should timeout immediately\n token?.expiresOnTimestamp ?? Date.now(),\n )\n .then((_token) => {\n refreshWorker = null;\n token = _token;\n tenantId = getTokenOptions.tenantId;\n return token;\n })\n .catch((reason) => {\n // We also should reset the refresher if we enter a failed state. All\n // existing awaiters will throw, but subsequent requests will start a\n // new retry chain.\n refreshWorker = null;\n token = null;\n tenantId = undefined;\n throw reason;\n });\n }\n\n return refreshWorker as Promise<AccessToken>;\n }\n\n return async (scopes: string | string[], tokenOptions: GetTokenOptions): Promise<AccessToken> => {\n //\n // Simple rules:\n // - If we MUST refresh, then return the refresh task, blocking\n // the pipeline until a token is available.\n // - If we SHOULD refresh, then run refresh but don't return it\n // (we can still use the cached token).\n // - Return the token, since it's fine if we didn't return in\n // step 1.\n //\n\n const hasClaimChallenge = Boolean(tokenOptions.claims);\n const tenantIdChanged = tenantId !== tokenOptions.tenantId;\n\n if (hasClaimChallenge) {\n // If we've received a claim, we know the existing token isn't valid\n // We want to clear it so that that refresh worker won't use the old expiration time as a timeout\n token = null;\n }\n\n // If the tenantId passed in token options is different to the one we have\n // Or if we are in claim challenge and the token was rejected and a new access token need to be issued, we need to\n // refresh the token with the new tenantId or token.\n const mustRefresh = tenantIdChanged || hasClaimChallenge || cycler.mustRefresh;\n\n if (mustRefresh) {\n return refresh(scopes, tokenOptions);\n }\n\n if (cycler.shouldRefresh) {\n refresh(scopes, tokenOptions);\n }\n\n return token as AccessToken;\n };\n}\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Allows the request to be aborted upon firing of the "abort" event.
|
|
3
|
-
* Compatible with the browser built-in AbortSignal and common polyfills.
|
|
4
|
-
*/
|
|
5
|
-
export interface AbortSignalLike {
|
|
6
|
-
/**
|
|
7
|
-
* Indicates if the signal has already been aborted.
|
|
8
|
-
*/
|
|
9
|
-
readonly aborted: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Add new "abort" event listener, only support "abort" event.
|
|
12
|
-
*/
|
|
13
|
-
addEventListener(type: "abort", listener: (this: AbortSignalLike, ev: any) => any, options?: any): void;
|
|
14
|
-
/**
|
|
15
|
-
* Remove "abort" event listener, only support "abort" event.
|
|
16
|
-
*/
|
|
17
|
-
removeEventListener(type: "abort", listener: (this: AbortSignalLike, ev: any) => any, options?: any): void;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=AbortSignalLike.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AbortSignalLike.js","sourceRoot":"","sources":["../../../src/abort-controller/AbortSignalLike.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Allows the request to be aborted upon firing of the \"abort\" event.\n * Compatible with the browser built-in AbortSignal and common polyfills.\n */\nexport interface AbortSignalLike {\n /**\n * Indicates if the signal has already been aborted.\n */\n readonly aborted: boolean;\n /**\n * Add new \"abort\" event listener, only support \"abort\" event.\n */\n addEventListener(\n type: \"abort\",\n listener: (this: AbortSignalLike, ev: any) => any,\n options?: any,\n ): void;\n /**\n * Remove \"abort\" event listener, only support \"abort\" event.\n */\n removeEventListener(\n type: \"abort\",\n listener: (this: AbortSignalLike, ev: any) => any,\n options?: any,\n ): void;\n}\n"]}
|