@okta/auth-foundation 0.6.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/LICENSE +189 -0
- package/THIRD-PARTY-NOTICES.md +5 -0
- package/dist/esm/Credential/Credential.js +219 -0
- package/dist/esm/Credential/Credential.js.map +1 -0
- package/dist/esm/Credential/CredentialCoordinator.js +160 -0
- package/dist/esm/Credential/CredentialCoordinator.js.map +1 -0
- package/dist/esm/Credential/CredentialDataSource.js +61 -0
- package/dist/esm/Credential/CredentialDataSource.js.map +1 -0
- package/dist/esm/Credential/TokenStorage.js +99 -0
- package/dist/esm/Credential/TokenStorage.js.map +1 -0
- package/dist/esm/FetchClient.js +91 -0
- package/dist/esm/FetchClient.js.map +1 -0
- package/dist/esm/Token.js +274 -0
- package/dist/esm/Token.js.map +1 -0
- package/dist/esm/TokenOrchestrator.js +56 -0
- package/dist/esm/TokenOrchestrator.js.map +1 -0
- package/dist/esm/core.js +59 -0
- package/dist/esm/core.js.map +1 -0
- package/dist/esm/crypto/index.js +60 -0
- package/dist/esm/crypto/index.js.map +1 -0
- package/dist/esm/errors/APIClientError.js +19 -0
- package/dist/esm/errors/APIClientError.js.map +1 -0
- package/dist/esm/errors/AuthSdkError.js +22 -0
- package/dist/esm/errors/AuthSdkError.js.map +1 -0
- package/dist/esm/errors/CredentialError.js +19 -0
- package/dist/esm/errors/CredentialError.js.map +1 -0
- package/dist/esm/errors/DPoPError.js +19 -0
- package/dist/esm/errors/DPoPError.js.map +1 -0
- package/dist/esm/errors/JWTError.js +19 -0
- package/dist/esm/errors/JWTError.js.map +1 -0
- package/dist/esm/errors/NetworkError.js +19 -0
- package/dist/esm/errors/NetworkError.js.map +1 -0
- package/dist/esm/errors/OAuth2Error.js +34 -0
- package/dist/esm/errors/OAuth2Error.js.map +1 -0
- package/dist/esm/errors/TokenError.js +19 -0
- package/dist/esm/errors/TokenError.js.map +1 -0
- package/dist/esm/errors/TokenOrchestratorError.js +19 -0
- package/dist/esm/errors/TokenOrchestratorError.js.map +1 -0
- package/dist/esm/http/APIClient.js +172 -0
- package/dist/esm/http/APIClient.js.map +1 -0
- package/dist/esm/http/oktaUserAgent.js +23 -0
- package/dist/esm/http/oktaUserAgent.js.map +1 -0
- package/dist/esm/http/requests/APIRequest.js +41 -0
- package/dist/esm/http/requests/APIRequest.js.map +1 -0
- package/dist/esm/http/requests/OAuth2Request.js +38 -0
- package/dist/esm/http/requests/OAuth2Request.js.map +1 -0
- package/dist/esm/http/wwwAuthenticate.js +48 -0
- package/dist/esm/http/wwwAuthenticate.js.map +1 -0
- package/dist/esm/index.js +64 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal.js +17 -0
- package/dist/esm/internal.js.map +1 -0
- package/dist/esm/jwt/IDTokenValidator.js +115 -0
- package/dist/esm/jwt/IDTokenValidator.js.map +1 -0
- package/dist/esm/jwt/JWK.js +48 -0
- package/dist/esm/jwt/JWK.js.map +1 -0
- package/dist/esm/jwt/JWT.js +159 -0
- package/dist/esm/jwt/JWT.js.map +1 -0
- package/dist/esm/jwt/TokenHashValidator.js +44 -0
- package/dist/esm/jwt/TokenHashValidator.js.map +1 -0
- package/dist/esm/oauth2/client.js +386 -0
- package/dist/esm/oauth2/client.js.map +1 -0
- package/dist/esm/oauth2/configuration.js +86 -0
- package/dist/esm/oauth2/configuration.js.map +1 -0
- package/dist/esm/oauth2/dpop/index.js +84 -0
- package/dist/esm/oauth2/dpop/index.js.map +1 -0
- package/dist/esm/oauth2/dpop/nonceCache.js +31 -0
- package/dist/esm/oauth2/dpop/nonceCache.js.map +1 -0
- package/dist/esm/oauth2/dpop/storage.js +39 -0
- package/dist/esm/oauth2/dpop/storage.js.map +1 -0
- package/dist/esm/oauth2/pkce.js +33 -0
- package/dist/esm/oauth2/pkce.js.map +1 -0
- package/dist/esm/oauth2/requests/UserInfo.js +40 -0
- package/dist/esm/oauth2/requests/UserInfo.js.map +1 -0
- package/dist/esm/platform/Platform.js +54 -0
- package/dist/esm/platform/Platform.js.map +1 -0
- package/dist/esm/platform/defaults.js +28 -0
- package/dist/esm/platform/defaults.js.map +1 -0
- package/dist/esm/types/oauth.js +41 -0
- package/dist/esm/types/oauth.js.map +1 -0
- package/dist/esm/utils/EventEmitter.js +63 -0
- package/dist/esm/utils/EventEmitter.js.map +1 -0
- package/dist/esm/utils/PromiseQueue.js +50 -0
- package/dist/esm/utils/PromiseQueue.js.map +1 -0
- package/dist/esm/utils/TaskBridge.js +242 -0
- package/dist/esm/utils/TaskBridge.js.map +1 -0
- package/dist/esm/utils/TimeCoordinator.js +77 -0
- package/dist/esm/utils/TimeCoordinator.js.map +1 -0
- package/dist/esm/utils/buildUrl.js +23 -0
- package/dist/esm/utils/buildUrl.js.map +1 -0
- package/dist/esm/utils/equality.js +38 -0
- package/dist/esm/utils/equality.js.map +1 -0
- package/dist/esm/utils/getSearchParam.js +24 -0
- package/dist/esm/utils/getSearchParam.js.map +1 -0
- package/dist/esm/utils/hashObject.js +30 -0
- package/dist/esm/utils/hashObject.js.map +1 -0
- package/dist/esm/utils/ignoreUndefineds.js +24 -0
- package/dist/esm/utils/ignoreUndefineds.js.map +1 -0
- package/dist/esm/utils/merge.js +47 -0
- package/dist/esm/utils/merge.js.map +1 -0
- package/dist/esm/utils/pause.js +20 -0
- package/dist/esm/utils/pause.js.map +1 -0
- package/dist/esm/utils/toRelativeUrl.js +19 -0
- package/dist/esm/utils/toRelativeUrl.js.map +1 -0
- package/dist/esm/utils/validators.js +32 -0
- package/dist/esm/utils/validators.js.map +1 -0
- package/dist/types/Credential/Credential.d.ts +292 -0
- package/dist/types/Credential/CredentialCoordinator.d.ts +103 -0
- package/dist/types/Credential/CredentialDataSource.d.ts +75 -0
- package/dist/types/Credential/TokenStorage.d.ts +116 -0
- package/dist/types/Credential/index.d.ts +8 -0
- package/dist/types/FetchClient.d.ts +28 -0
- package/dist/types/Token.d.ts +246 -0
- package/dist/types/TokenOrchestrator.d.ts +64 -0
- package/dist/types/core.d.ts +21 -0
- package/dist/types/crypto/index.d.ts +32 -0
- package/dist/types/errors/APIClientError.d.ts +12 -0
- package/dist/types/errors/AuthSdkError.d.ts +20 -0
- package/dist/types/errors/CredentialError.d.ts +12 -0
- package/dist/types/errors/DPoPError.d.ts +12 -0
- package/dist/types/errors/JWTError.d.ts +12 -0
- package/dist/types/errors/NetworkError.d.ts +12 -0
- package/dist/types/errors/OAuth2Error.d.ts +17 -0
- package/dist/types/errors/TokenError.d.ts +12 -0
- package/dist/types/errors/TokenOrchestratorError.d.ts +12 -0
- package/dist/types/errors/index.d.ts +13 -0
- package/dist/types/http/APIClient.d.ts +113 -0
- package/dist/types/http/index.d.ts +6 -0
- package/dist/types/http/oktaUserAgent.d.ts +8 -0
- package/dist/types/http/requests/APIRequest.d.ts +19 -0
- package/dist/types/http/requests/OAuth2Request.d.ts +30 -0
- package/dist/types/http/wwwAuthenticate.d.ts +32 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/internal.d.ts +8 -0
- package/dist/types/jwt/IDTokenValidator.d.ts +38 -0
- package/dist/types/jwt/JWK.d.ts +31 -0
- package/dist/types/jwt/JWT.d.ts +107 -0
- package/dist/types/jwt/TokenHashValidator.d.ts +13 -0
- package/dist/types/jwt/index.d.ts +8 -0
- package/dist/types/oauth2/client.d.ts +120 -0
- package/dist/types/oauth2/configuration.d.ts +56 -0
- package/dist/types/oauth2/dpop/index.d.ts +70 -0
- package/dist/types/oauth2/dpop/nonceCache.d.ts +27 -0
- package/dist/types/oauth2/dpop/storage.d.ts +27 -0
- package/dist/types/oauth2/dpop/types.d.ts +52 -0
- package/dist/types/oauth2/pkce.d.ts +23 -0
- package/dist/types/oauth2/requests/UserInfo.d.ts +32 -0
- package/dist/types/platform/Platform.d.ts +121 -0
- package/dist/types/platform/defaults.d.ts +10 -0
- package/dist/types/types/index.d.ts +6 -0
- package/dist/types/types/lib.d.ts +106 -0
- package/dist/types/types/oauth.d.ts +117 -0
- package/dist/types/types/openid.d.ts +320 -0
- package/dist/types/utils/EventEmitter.d.ts +29 -0
- package/dist/types/utils/PromiseQueue.d.ts +18 -0
- package/dist/types/utils/TaskBridge.d.ts +153 -0
- package/dist/types/utils/TimeCoordinator.d.ts +49 -0
- package/dist/types/utils/buildUrl.d.ts +10 -0
- package/dist/types/utils/equality.d.ts +19 -0
- package/dist/types/utils/getSearchParam.d.ts +13 -0
- package/dist/types/utils/hashObject.d.ts +6 -0
- package/dist/types/utils/ignoreUndefineds.d.ts +14 -0
- package/dist/types/utils/index.d.ts +13 -0
- package/dist/types/utils/merge.d.ts +16 -0
- package/dist/types/utils/pause.d.ts +15 -0
- package/dist/types/utils/toRelativeUrl.d.ts +10 -0
- package/dist/types/utils/validators.d.ts +6 -0
- package/package.json +1 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
3
|
+
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
4
|
+
*
|
|
5
|
+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
8
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
*
|
|
10
|
+
* See the License for the specific language governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function toRelativeUrl(url) {
|
|
14
|
+
url = new URL(url);
|
|
15
|
+
return url.href.replace(url.origin, '');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { toRelativeUrl };
|
|
19
|
+
//# sourceMappingURL=toRelativeUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toRelativeUrl.js","sources":["../../../../src/utils/toRelativeUrl.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;AAWM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAE,CAAA,CAAA,CAAiB,CAAA,CAAA,CAAA;AAC9C,CAAA,CAAA,CAAA,CAAA,GAAG,CAAA,CAAA,CAAG,CAAA,CAAA,CAAA,CAAI,CAAA,CAAA,CAAG,CAAC,GAAG,CAAC,CAAA;AAClB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAG,CAAC,CAAA,CAAA,CAAA,CAAI,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAC,CAAA,CAAA,CAAG,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAE,CAAA,CAAE,CAAC,CAAA;AACzC,CAAA;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
3
|
+
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
4
|
+
*
|
|
5
|
+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
8
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
*
|
|
10
|
+
* See the License for the specific language governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function validateString(input) {
|
|
14
|
+
return typeof input === 'string' && input.length !== 0;
|
|
15
|
+
}
|
|
16
|
+
function validateURL(input, allowHttp = false) {
|
|
17
|
+
if (!validateString(input)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const url = new URL(input);
|
|
22
|
+
if (allowHttp) {
|
|
23
|
+
return url.protocol === 'https:' || url.protocol === 'http:';
|
|
24
|
+
}
|
|
25
|
+
return url.protocol === 'https:';
|
|
26
|
+
}
|
|
27
|
+
catch (err) { }
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { validateString, validateURL };
|
|
32
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sources":["../../../../src/utils/validators.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;AAOM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAc,CAAE,CAAA,CAAA,CAAA,CAAA,CAAc,CAAA,CAAA,CAAA;IAC5C,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,IAAI,CAAA,CAAA,CAAA,CAAA,CAAK,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAK,CAAC,CAAA;AACxD,CAAA;SAEgB,WAAW,CAAE,CAAA,CAAA,CAAA,CAAA,CAAc,EAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAG,KAAK,CAAA,CAAA,CAAA;AAC5D,CAAA,CAAA,CAAA,CAAA,IAAI,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAc,CAAC,CAAA,CAAA,CAAA,CAAA,CAAK,CAAC,CAAA,CAAE,CAAA;AAC1B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,OAAO,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA;IACd,CAAA;AACA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,CAAA;AACF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,MAAM,CAAA,CAAA,CAAG,CAAA,CAAA,CAAG,IAAI,CAAA,CAAA,CAAG,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAA,CAAA,CAAA,CAAI,SAAS,CAAA,CAAE,CAAA;YACb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAG,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,CAAA,CAAA,CAAA,CAAI,CAAA,CAAA,CAAG,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA;QAC9D,CAAA;AACA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAG,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,KAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,CAAA;IAClC,CAAA;AAEA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAG,CAAA,CAAE,CAAA,CAAC,CAAA;AACb,CAAA,CAAA,CAAA,CAAA,OAAO,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA;AACd,CAAA;;"}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Credential
|
|
3
|
+
*/
|
|
4
|
+
import { type RequestAuthorizer, type RequestAuthorizerInit, type JsonRecord, type JSONSerializable, type Seconds } from '../types/index.ts';
|
|
5
|
+
import type { OAuth2Client } from '../oauth2/client.ts';
|
|
6
|
+
import { Token } from '../Token.ts';
|
|
7
|
+
import { UserInfo } from '../oauth2/requests/UserInfo.ts';
|
|
8
|
+
import { EventEmitter } from '../utils/EventEmitter.ts';
|
|
9
|
+
import { type CredentialCoordinator, type CredentialCoordinatorEvents } from './CredentialCoordinator.ts';
|
|
10
|
+
type CredentialEvents = {
|
|
11
|
+
'credential_added': {
|
|
12
|
+
credential: Credential;
|
|
13
|
+
};
|
|
14
|
+
'credential_removed': {
|
|
15
|
+
id: string;
|
|
16
|
+
};
|
|
17
|
+
'tags_updated': {
|
|
18
|
+
id: string;
|
|
19
|
+
tags: string[];
|
|
20
|
+
};
|
|
21
|
+
} & Omit<CredentialCoordinatorEvents, 'credential_added' | 'credential_removed'>;
|
|
22
|
+
/**
|
|
23
|
+
* Wrapper around a {@link Token.Token | Token}, providing methods to interact with Tokens without the hassle of managing them
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare class Credential implements RequestAuthorizer, JSONSerializable {
|
|
28
|
+
protected static readonly emitter: EventEmitter<CredentialEvents>;
|
|
29
|
+
/** @internal */
|
|
30
|
+
protected static _coordinator: CredentialCoordinator;
|
|
31
|
+
/** @internal */
|
|
32
|
+
static get coordinator(): CredentialCoordinator;
|
|
33
|
+
/** @internal */
|
|
34
|
+
static set coordinator(coordinator: CredentialCoordinator);
|
|
35
|
+
/** @internal */
|
|
36
|
+
protected _token: Token;
|
|
37
|
+
/** @internal */
|
|
38
|
+
protected _refreshPromise: Promise<void> | null;
|
|
39
|
+
/** @internal */
|
|
40
|
+
protected _oauth2: OAuth2Client;
|
|
41
|
+
/** @internal */
|
|
42
|
+
protected _metadata: Token.Metadata;
|
|
43
|
+
/** @internal */
|
|
44
|
+
protected _userInfo: UserInfo | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* @remarks
|
|
47
|
+
* Do not use directly, use {@link store | Credential.store} instead
|
|
48
|
+
*/
|
|
49
|
+
constructor(token: Token, client: OAuth2Client, metadata?: Token.Metadata);
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
* accesses a derived class' coordinator rather than the default Credential impl's
|
|
53
|
+
*/
|
|
54
|
+
protected get coordinator(): CredentialCoordinator;
|
|
55
|
+
/**
|
|
56
|
+
* Returns instance of {@link OAuth2.OAuth2Client | OAuth2Client} used to construct {@link Credential}
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
get oauth2(): OAuth2Client;
|
|
61
|
+
/**
|
|
62
|
+
* Bind an event listener
|
|
63
|
+
*
|
|
64
|
+
* @param event - event name
|
|
65
|
+
* @param callback - event handler
|
|
66
|
+
*
|
|
67
|
+
* @group Events
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* Credential.on(Events.CREDENTIAL_REFRESHED, credential => {
|
|
71
|
+
* // do something with credential
|
|
72
|
+
* });
|
|
73
|
+
*/
|
|
74
|
+
static on(...args: Parameters<EventEmitter<CredentialEvents>['on']>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Removes active event listeners
|
|
77
|
+
*
|
|
78
|
+
* @param event - event name
|
|
79
|
+
* @param callback - the event handler previously bound via {@link on | Credential.on}
|
|
80
|
+
*
|
|
81
|
+
* @group Events
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* Credential.off(Events.CREDENTIAL_REFRESHED);
|
|
85
|
+
*/
|
|
86
|
+
static off(...args: Parameters<EventEmitter<CredentialEvents>['off']>): void;
|
|
87
|
+
/**
|
|
88
|
+
* @group Static Accessors
|
|
89
|
+
*/
|
|
90
|
+
static getDefault(): Promise<Credential | null>;
|
|
91
|
+
/**
|
|
92
|
+
* @group Static Accessors
|
|
93
|
+
*/
|
|
94
|
+
static setDefault(cred: Credential | null): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Returns array of all Credential ids
|
|
97
|
+
*
|
|
98
|
+
* @group Static Accessors
|
|
99
|
+
*/
|
|
100
|
+
static allIDs(): Promise<string[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns number of Credential instances
|
|
103
|
+
*
|
|
104
|
+
* @group Static Accessors
|
|
105
|
+
*/
|
|
106
|
+
static get size(): number;
|
|
107
|
+
/**
|
|
108
|
+
* Writes `token` to storage and returns a {@link Credential} instance
|
|
109
|
+
*
|
|
110
|
+
* @param token - Object representing the token to be managed by returned Credential instance
|
|
111
|
+
* @param tags - List of strings that can be used to ease Credential retrieval
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* const adminToken = await fetchAdminToken();
|
|
115
|
+
* const token = new Token(adminToken);
|
|
116
|
+
* Credential.store(token, ['admin']);
|
|
117
|
+
*
|
|
118
|
+
* @group Factory Methods
|
|
119
|
+
*
|
|
120
|
+
*/
|
|
121
|
+
static store(token: Token, tags?: string[]): Promise<Credential>;
|
|
122
|
+
/**
|
|
123
|
+
* Returns {@link Credential} instance with corresponding {@link Credential.id | id}
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
* This method can be used to retreive a specific {@link Credential}, however its recommended to use
|
|
127
|
+
* {@link Credential.getDefault} or {@link Credential.find} to query by {@link Credential.tags | tags} instead
|
|
128
|
+
*
|
|
129
|
+
* @group Static Methods
|
|
130
|
+
*/
|
|
131
|
+
static with(id: string): Promise<Credential | null>;
|
|
132
|
+
/**
|
|
133
|
+
* Returns all Credential instances where `matcher` function returns `true`
|
|
134
|
+
*
|
|
135
|
+
* @param matcher - Function which takes `meta` as first argument. Returns `true` if Credential should
|
|
136
|
+
* be included, `false` otherwise
|
|
137
|
+
*
|
|
138
|
+
* *Shorthand* Pass an object with any key in {@link Token.Token.Metadata:TYPE | Token.Metadata} and a string value to match on.
|
|
139
|
+
*
|
|
140
|
+
* @group Static Methods
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* // find Credentials by tag 'foo'
|
|
144
|
+
* Credential.find(meta => meta?.tags?.includes('foo'));
|
|
145
|
+
*
|
|
146
|
+
* // shorthand - find Credentials by tag 'foo'
|
|
147
|
+
* Credential.find({ tags: 'foo' });
|
|
148
|
+
*/
|
|
149
|
+
static find(matcher: ((meta: Token.Metadata) => boolean) | {
|
|
150
|
+
[key in keyof Token.Metadata]?: string | string[];
|
|
151
|
+
}): Promise<Credential[]>;
|
|
152
|
+
/**
|
|
153
|
+
* Removes all {@link Credential} instances and clears storage
|
|
154
|
+
*
|
|
155
|
+
* @group Static Methods
|
|
156
|
+
*/
|
|
157
|
+
static clear(): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Compares 2 Credential instances to determine if they represent the same token
|
|
160
|
+
*
|
|
161
|
+
* @group Static Methods
|
|
162
|
+
*/
|
|
163
|
+
static isEqual(lhs: Credential, rhs: Credential): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* The {@link Token.Token | Token} instance {@link Credential} is associated with
|
|
166
|
+
*
|
|
167
|
+
* @remarks
|
|
168
|
+
* This value may change, from operations like {@link Credential.refresh},
|
|
169
|
+
* however the {@link Token.Token.id | Token.id} will remain consistent
|
|
170
|
+
*/
|
|
171
|
+
get token(): Token;
|
|
172
|
+
/** @internal */
|
|
173
|
+
protected set token(token: Token);
|
|
174
|
+
/**
|
|
175
|
+
* Short for `this.token.id`
|
|
176
|
+
*/
|
|
177
|
+
get id(): string;
|
|
178
|
+
/**
|
|
179
|
+
* Array of tags associated with {@link Credential}. Used for retrieval
|
|
180
|
+
*/
|
|
181
|
+
get tags(): string[];
|
|
182
|
+
/**
|
|
183
|
+
* Updates tags associated with {@link Credential}
|
|
184
|
+
*
|
|
185
|
+
* @remarks
|
|
186
|
+
* This is *not* merge operation
|
|
187
|
+
*
|
|
188
|
+
* @param tags - tags to be associated with {@link Credential}
|
|
189
|
+
*/
|
|
190
|
+
setTags(tags?: string[]): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Removes {@link Credential} from storage
|
|
193
|
+
*
|
|
194
|
+
* @remarks
|
|
195
|
+
* **NOTE:** this method *does not* revoke tokens
|
|
196
|
+
*
|
|
197
|
+
* @see {@link revoke | Credential.prototype.revoke}
|
|
198
|
+
*/
|
|
199
|
+
remove(): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Helper method to get a `Authorization` header, expressed as an object
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* cred.getAuthHeader();
|
|
205
|
+
* // { 'Authorization': 'Bearer ***********' }
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* const data = await fetch('resource/server', { headers: { ...cred.getAuthHeader() }})
|
|
209
|
+
*
|
|
210
|
+
*/
|
|
211
|
+
getAuthHeader(): {
|
|
212
|
+
Authorization: string;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* A utility method which matches the signature of [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
|
|
216
|
+
* a [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) instance with a predefined `Authorization` header
|
|
217
|
+
*/
|
|
218
|
+
authorize(input: string | URL | Request, init?: RequestAuthorizerInit): Promise<Request>;
|
|
219
|
+
toJSON(): JsonRecord;
|
|
220
|
+
/** @internal */
|
|
221
|
+
protected observeToken(): void;
|
|
222
|
+
/**
|
|
223
|
+
* Attempts to refresh the represented `token`
|
|
224
|
+
*
|
|
225
|
+
* @remarks
|
|
226
|
+
* Upon successful refresh, the `token` will be replaced with a new
|
|
227
|
+
* {@link Token.Token | Token} instance, however the `id` property will remain consistent
|
|
228
|
+
*
|
|
229
|
+
* @group OAuth2 Methods
|
|
230
|
+
*
|
|
231
|
+
* @throws {@link Core.OAuth2Error | OAuth2Error } if refresh fails
|
|
232
|
+
*/
|
|
233
|
+
refresh(): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Renews `token` if the will expire within the grace period
|
|
236
|
+
*
|
|
237
|
+
* @remarks
|
|
238
|
+
* Expiration calculation is performed on the browser via `TimeCoordinator`
|
|
239
|
+
*
|
|
240
|
+
* @group OAuth2 Methods
|
|
241
|
+
*
|
|
242
|
+
* @throws {@link Core.OAuth2Error | OAuth2Error} if refresh fails
|
|
243
|
+
*/
|
|
244
|
+
refreshIfNeeded(gracePeriod?: Seconds): Promise<void>;
|
|
245
|
+
/**
|
|
246
|
+
* Revokes either {@link Token.Token.accessToken | token.accessToken} or
|
|
247
|
+
* {@link Token.Token.refreshToken | token.refreshToken} or both
|
|
248
|
+
*
|
|
249
|
+
* @remarks
|
|
250
|
+
* * If `RevokeType.ALL`, {@link Credential} will be removed
|
|
251
|
+
*
|
|
252
|
+
* @group OAuth2 Methods
|
|
253
|
+
*
|
|
254
|
+
* @throws {@link Core.OAuth2Error | OAuth2Error} if revocation fails
|
|
255
|
+
*
|
|
256
|
+
* @see
|
|
257
|
+
* {@link https://developer.okta.com/docs/api/openapi/okta-oauth/oauth/tag/CustomAS/#tag/CustomAS/operation/revokeCustomAS | Okta Docs}
|
|
258
|
+
* {@link https://oauth.net/2/token-revocation/ | OAuth2 Reference}
|
|
259
|
+
* {@link https://datatracker.ietf.org/doc/html/rfc7009 | RFC}
|
|
260
|
+
*/
|
|
261
|
+
revoke(type?: Token.RevokeType): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Performs introspect on a specific token
|
|
264
|
+
*
|
|
265
|
+
* @param kind - The specific token to introspect.
|
|
266
|
+
* Must be available in {@link Credential.token}
|
|
267
|
+
*
|
|
268
|
+
* @group OAuth2 Methods
|
|
269
|
+
*
|
|
270
|
+
* @throws {@link Core.OAuth2Error | OAuth2Error}
|
|
271
|
+
*
|
|
272
|
+
* @see
|
|
273
|
+
* {@link https://developer.okta.com/docs/api/openapi/okta-oauth/oauth/tag/CustomAS/#tag/CustomAS/operation/introspectCustomAS | Okta Docs}
|
|
274
|
+
* {@link https://oauth.net/2/token-introspection/ | OAuth2 Reference}
|
|
275
|
+
*/
|
|
276
|
+
introspect(kind: Token.Kind): Promise<Token.IntrospectResponse>;
|
|
277
|
+
/**
|
|
278
|
+
* Performs OIDC UserInfo request
|
|
279
|
+
*
|
|
280
|
+
* @param ignoreCache - When `false` any previously fetched result will be returned rather than making a network request. Defaults to `false`
|
|
281
|
+
*
|
|
282
|
+
* @group OAuth2 Methods
|
|
283
|
+
*
|
|
284
|
+
* @throws {@link Core.OAuth2Error | OAuth2Error}
|
|
285
|
+
*
|
|
286
|
+
* @see
|
|
287
|
+
* {@link https://developer.okta.com/docs/api/openapi/okta-oauth/oauth/tag/CustomAS/#tag/CustomAS/operation/userinfoCustomAS | Okta Docs}
|
|
288
|
+
* {@link https://openid.net/specs/openid-connect-core-1_0.html#UserInfo | OIDC Spec}
|
|
289
|
+
*/
|
|
290
|
+
userInfo(ignoreCache?: boolean): Promise<UserInfo>;
|
|
291
|
+
}
|
|
292
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Credential
|
|
4
|
+
*/
|
|
5
|
+
import type { OAuth2Client } from '../oauth2/client.ts';
|
|
6
|
+
import type { Credential } from './Credential.ts';
|
|
7
|
+
import { Token } from '../Token.ts';
|
|
8
|
+
import { EventEmitter } from '../utils/EventEmitter.ts';
|
|
9
|
+
import { type CredentialDataSource, type CredentialDataSourceEvents } from './CredentialDataSource.ts';
|
|
10
|
+
import { TokenStorage, TokenStorageEvents } from './TokenStorage.ts';
|
|
11
|
+
export type CredentialCoordinatorEvents = {
|
|
12
|
+
'credential_expired': {
|
|
13
|
+
credential: Credential;
|
|
14
|
+
};
|
|
15
|
+
'credential_refreshed': {
|
|
16
|
+
credential: Credential;
|
|
17
|
+
};
|
|
18
|
+
'cleared': void;
|
|
19
|
+
} & Pick<TokenStorageEvents, 'default_changed' | 'metadata_updated' | 'token_replaced'> & CredentialDataSourceEvents;
|
|
20
|
+
/**
|
|
21
|
+
* @public @interface
|
|
22
|
+
*
|
|
23
|
+
* Holds the implementation of most {@link Credential} methods. Bridges the
|
|
24
|
+
* {@link CredentialDataSource} and {@link TokenStorage} layers together
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Default implementation provided
|
|
28
|
+
*/
|
|
29
|
+
export interface CredentialCoordinator {
|
|
30
|
+
emitter: EventEmitter<CredentialCoordinatorEvents>;
|
|
31
|
+
/**
|
|
32
|
+
* Represents {@link Credential.getDefault}, backed by {@link CredentialCoordinator.tokenStorage | TokenStorage}
|
|
33
|
+
*/
|
|
34
|
+
getDefault(): Promise<Credential | null>;
|
|
35
|
+
setDefault(cred: Credential | null): Promise<void>;
|
|
36
|
+
get tokenStorage(): TokenStorage;
|
|
37
|
+
/**
|
|
38
|
+
* Writes the provided {@link Token.Token | Token} (and {@link Token.Token.Metadata:TYPE | Token.Metadata}) to storage and creates a {@link Credential}
|
|
39
|
+
* instance to represent the {@link Token.Token | Token} via the {@link CredentialDataSource}
|
|
40
|
+
*
|
|
41
|
+
* @param token - the {@link Token.Token | Token} to store
|
|
42
|
+
* @param tags - an array of developer-provided tags to associate with a {@link Token.Token | Token}.
|
|
43
|
+
* Used by {@link Credential.find} queries
|
|
44
|
+
*/
|
|
45
|
+
store(token: Token, tags: string[]): Promise<Credential>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves a {@link Credential} for the provided `id` from storage
|
|
48
|
+
*/
|
|
49
|
+
with(id: string): Promise<Credential | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Uses stored {@link Token.Token.Metadata:TYPE | Token.Metadata} to match stored {@link Token.Token | Tokens} by certain criteria
|
|
52
|
+
*/
|
|
53
|
+
find(matcher: (meta: Token.Metadata) => boolean): Promise<Credential[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Removes the provided {@link Credential} from storage and {@link CredentialDataSource}
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* **NOTE:** This does *not* {@link Credential.revoke | revoke} tokens!
|
|
59
|
+
*/
|
|
60
|
+
remove(cred: Credential): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Clears both {@link TokenStorage} and {@link CredentialDataSource}
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* **NOTE:** This does *not* {@link Credential.revoke | revoke} tokens!
|
|
66
|
+
*/
|
|
67
|
+
clear(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Returns all token {@link Token.Token.id | ids} in storage
|
|
70
|
+
*/
|
|
71
|
+
allIDs(): Promise<string[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the number of recorded {@link Credential} instances in the {@link CredentialDataSource}
|
|
74
|
+
*/
|
|
75
|
+
readonly size: number;
|
|
76
|
+
}
|
|
77
|
+
/** @internal */
|
|
78
|
+
export declare class CredentialCoordinatorImpl implements CredentialCoordinator {
|
|
79
|
+
readonly emitter: EventEmitter<CredentialCoordinatorEvents>;
|
|
80
|
+
protected readonly expiryTimeouts: {
|
|
81
|
+
[key: string]: ReturnType<typeof setTimeout>;
|
|
82
|
+
};
|
|
83
|
+
protected _default: Credential | null | undefined;
|
|
84
|
+
protected _credentialDataSource: CredentialDataSource;
|
|
85
|
+
protected _tokenStorage: TokenStorage;
|
|
86
|
+
constructor(CredentialConstructor: new (token: Token, client: OAuth2Client) => Credential);
|
|
87
|
+
get credentialDataSource(): CredentialDataSource;
|
|
88
|
+
set credentialDataSource(dataSource: CredentialDataSource);
|
|
89
|
+
get tokenStorage(): TokenStorage;
|
|
90
|
+
set tokenStorage(tokenStorage: TokenStorage);
|
|
91
|
+
protected clearExpireEventTimeout(id: string): void;
|
|
92
|
+
protected addExpireEventTimeout(credential: Credential): void;
|
|
93
|
+
getDefault(): Promise<Credential | null>;
|
|
94
|
+
setDefault(cred: Credential | null): Promise<void>;
|
|
95
|
+
store(token: Token, tags?: string[]): Promise<Credential>;
|
|
96
|
+
with(id: string): Promise<Credential | null>;
|
|
97
|
+
find(matcher: (meta: Token.Metadata) => boolean): Promise<Credential[]>;
|
|
98
|
+
remove(cred: Credential): Promise<void>;
|
|
99
|
+
clear(localOnly?: boolean): Promise<void>;
|
|
100
|
+
allIDs(): Promise<string[]>;
|
|
101
|
+
get size(): number;
|
|
102
|
+
protected loadDefaultCredential(): Promise<Credential | null>;
|
|
103
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Credential
|
|
4
|
+
*/
|
|
5
|
+
import type { Token } from '../Token.ts';
|
|
6
|
+
import type { Credential } from './Credential.ts';
|
|
7
|
+
import { EventEmitter } from '../utils/EventEmitter.ts';
|
|
8
|
+
import { OAuth2Client } from '../oauth2/client.ts';
|
|
9
|
+
import { ConfigurationParams } from '../types/index.ts';
|
|
10
|
+
export type CredentialDataSourceEvents = {
|
|
11
|
+
credential_added: {
|
|
12
|
+
dataSource: CredentialDataSource;
|
|
13
|
+
credential: Credential;
|
|
14
|
+
};
|
|
15
|
+
credential_removed: {
|
|
16
|
+
dataSource: CredentialDataSource;
|
|
17
|
+
id: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @public @interface
|
|
22
|
+
*
|
|
23
|
+
* Prevents multiple instances of {@link Credential} from existing for the same {@link Token.Token | Token}
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Default implementation provided
|
|
27
|
+
*/
|
|
28
|
+
export interface CredentialDataSource {
|
|
29
|
+
readonly emitter: EventEmitter<CredentialDataSourceEvents>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the number of {@link Credential}s recorded in the {@link CredentialDataSource}
|
|
32
|
+
*/
|
|
33
|
+
readonly size: number;
|
|
34
|
+
/**
|
|
35
|
+
* Checks {@link CredentialDataSource} for an existing {@link Credential} instance which
|
|
36
|
+
* represents the provided {@link Token.Token | Token}.
|
|
37
|
+
*/
|
|
38
|
+
hasCredential(token: Token): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Checks {@link CredentialDataSource} for an existing {@link Credential} instance which
|
|
41
|
+
* represents the provided {@link Token.Token | Token}. If one does not exist, a new {@link Credential}
|
|
42
|
+
* instance is created (and recorded within the {@link CredentialDataSource})
|
|
43
|
+
*/
|
|
44
|
+
credentialFor(token: Token, metadata?: Token.Metadata): Credential;
|
|
45
|
+
/**
|
|
46
|
+
* Removes provided {@link Credential} instance from the {@link CredentialDataSource}
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* **NOTE:** This does *not* {@link Credential.revoke | revoke} the represented token.
|
|
50
|
+
* They are only removed from the {@link CredentialDataSource}!
|
|
51
|
+
*/
|
|
52
|
+
remove(cred: Credential | string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Clears all {@link Credential} instances from the {@link CredentialDataSource}
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* **NOTE:** This does *not* {@link Credential.revoke | revoke} tokens.
|
|
58
|
+
* They are only removed from the {@link CredentialDataSource}!
|
|
59
|
+
*/
|
|
60
|
+
clear(): void;
|
|
61
|
+
}
|
|
62
|
+
/** @internal */
|
|
63
|
+
export declare class DefaultCredentialDataSource implements CredentialDataSource {
|
|
64
|
+
protected readonly CredentialConstructor: new (...args: ConstructorParameters<typeof Credential>) => Credential;
|
|
65
|
+
protected readonly credentials: Map<string, Credential>;
|
|
66
|
+
readonly emitter: EventEmitter<CredentialDataSourceEvents>;
|
|
67
|
+
constructor(CredentialConstructor: new (...args: ConstructorParameters<typeof Credential>) => Credential);
|
|
68
|
+
protected createOAuth2Client(params: ConfigurationParams): OAuth2Client;
|
|
69
|
+
protected createCredential(token: Token, metadata?: Token.Metadata): Credential;
|
|
70
|
+
hasCredential(token: Token): boolean;
|
|
71
|
+
credentialFor(token: Token, metadata?: Token.Metadata): Credential;
|
|
72
|
+
remove(cred: Credential | string): void;
|
|
73
|
+
clear(): void;
|
|
74
|
+
get size(): number;
|
|
75
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Credential
|
|
4
|
+
*/
|
|
5
|
+
import { Token } from '../Token.ts';
|
|
6
|
+
import { EventEmitter } from '../utils/EventEmitter.ts';
|
|
7
|
+
type TokenStorageEvent = {
|
|
8
|
+
storage: TokenStorage;
|
|
9
|
+
id: string;
|
|
10
|
+
};
|
|
11
|
+
export type TokenStorageEvents = {
|
|
12
|
+
'token_added': TokenStorageEvent & {
|
|
13
|
+
token: Token;
|
|
14
|
+
};
|
|
15
|
+
'token_removed': TokenStorageEvent;
|
|
16
|
+
'token_replaced': TokenStorageEvent & {
|
|
17
|
+
token: Token;
|
|
18
|
+
};
|
|
19
|
+
'default_changed': Omit<TokenStorageEvent, 'id'> & {
|
|
20
|
+
id: string | null;
|
|
21
|
+
};
|
|
22
|
+
'metadata_updated': TokenStorageEvent & {
|
|
23
|
+
metadata: Token.Metadata;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @public @interface
|
|
28
|
+
*
|
|
29
|
+
* Defines interface for token storage. {@link Token.Token | Token} and {@link Token.Token.Metadata:TYPE | Token.Metadata} are treated as independent entities,
|
|
30
|
+
* which enables them to be stored in different locations. This may be more relevant in mobile environments, where {@link Token.Token | Token} data can be
|
|
31
|
+
* written to a secure location (which requires biometrics to access) and {@link Token.Token.Metadata:TYPE | Token.Metadata}, containing only non-sensitive info
|
|
32
|
+
* can be stored in a more accessible location and used to query which tokens are available (without prompting biometrics)
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Default implementation provided based on {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage | localStorage}
|
|
36
|
+
*/
|
|
37
|
+
export interface TokenStorage {
|
|
38
|
+
readonly emitter: EventEmitter<TokenStorageEvents>;
|
|
39
|
+
/**
|
|
40
|
+
* In memory cached value of the {@link Credential.getDefault | default Credential}'s id
|
|
41
|
+
*/
|
|
42
|
+
readonly defaultTokenId: string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Updates the stored {@link Credential.getDefault | default Credential} id
|
|
45
|
+
*/
|
|
46
|
+
setDefaultTokenId(id: string | null): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Returns all token {@link Token.Token.id | ids} in storage
|
|
49
|
+
*/
|
|
50
|
+
allIDs(): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Writes a {@link Token.Token | Token} to storage
|
|
53
|
+
*
|
|
54
|
+
* @param token - raw JSON representation of {@link Token.Token | Token}
|
|
55
|
+
* @param metadata - non-sensitive data regarding the stored {@link Token.Token | Token} which will be used in storage queries
|
|
56
|
+
*/
|
|
57
|
+
add(token: Token, metadata?: Token.Metadata): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Updates the {@link Token.Token | Token} value in storage for a given {@link Token.Token.id | id}.
|
|
60
|
+
* Used by operations like {@link Credential.refresh}
|
|
61
|
+
*/
|
|
62
|
+
replace(id: string, token: Token): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Removes the {@link Token.Token | Token} value for a given {@link Token.Token.id | id} from storage
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* **NOTE:** This does *not* {@link Credential.revoke | revoke} tokens. They are only removed from storage!
|
|
68
|
+
*/
|
|
69
|
+
remove(id: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Retrieves a {@link Token.Token | Token} from storage
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* This may prompt user for biometrics in certain mobile environments
|
|
75
|
+
*/
|
|
76
|
+
get(id: string): Promise<Token | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Retieves {@link Token.Token.Metadata:TYPE | Token.Metadata} for a given {@link Token.Token.id | id}
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* {@link Token.Token.Metadata:TYPE | Token.Metadata} will be written to less-protected location and therefore will not prompt biometrics
|
|
82
|
+
*/
|
|
83
|
+
getMetadata(id: string): Promise<Token.Metadata | null>;
|
|
84
|
+
/**
|
|
85
|
+
* Writes {@link Token.Token.Metadata:TYPE | Token.Metadata} for a given {@link Token.Token | Token} to storage
|
|
86
|
+
*/
|
|
87
|
+
setMetadata(metadata: Token.Metadata): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Clears all {@link Token.Token | Token} instances from storage
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* **NOTE:** This does *not* {@link Credential.revoke | revoke} tokens. They are only removed from storage!
|
|
93
|
+
*/
|
|
94
|
+
clear(): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A simple Map-based TokenStorage implementation. Not necessarily intended for production use!
|
|
98
|
+
*
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
export declare class DefaultTokenStorage implements TokenStorage {
|
|
102
|
+
#private;
|
|
103
|
+
readonly emitter: EventEmitter<TokenStorageEvents>;
|
|
104
|
+
get defaultTokenId(): string | null;
|
|
105
|
+
setDefaultTokenId(id: string | null): Promise<void>;
|
|
106
|
+
protected saveDefault(id: string | null): void;
|
|
107
|
+
allIDs(): Promise<string[]>;
|
|
108
|
+
add(token: Token, metadata?: Token.Metadata | undefined): Promise<void>;
|
|
109
|
+
replace(id: string, token: Token): Promise<void>;
|
|
110
|
+
remove(id: string): Promise<void>;
|
|
111
|
+
get(id: string): Promise<Token | null>;
|
|
112
|
+
getMetadata(id: string): Promise<Token.Metadata | null>;
|
|
113
|
+
setMetadata(metadata: Token.Metadata): Promise<void>;
|
|
114
|
+
clear(): Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
export {};
|