@okta/okta-auth-js 6.1.0 → 6.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/README.md +53 -23
- package/cjs/AuthStateManager.js +14 -7
- package/cjs/AuthStateManager.js.map +1 -1
- package/cjs/OktaAuth.js +30 -14
- package/cjs/OktaAuth.js.map +1 -1
- package/cjs/OktaUserAgent.js +2 -2
- package/cjs/PromiseQueue.js +9 -2
- package/cjs/PromiseQueue.js.map +1 -1
- package/cjs/ServiceManager.js +195 -0
- package/cjs/ServiceManager.js.map +1 -0
- package/cjs/TokenManager.js +6 -14
- package/cjs/TokenManager.js.map +1 -1
- package/cjs/TransactionManager.js +11 -5
- package/cjs/TransactionManager.js.map +1 -1
- package/cjs/browser/browserStorage.js +31 -25
- package/cjs/browser/browserStorage.js.map +1 -1
- package/cjs/crypto/node.js +19 -13
- package/cjs/crypto/node.js.map +1 -1
- package/cjs/idx/authenticator/Authenticator.js.map +1 -1
- package/cjs/idx/authenticator/OktaPassword.js +12 -3
- package/cjs/idx/authenticator/OktaPassword.js.map +1 -1
- package/cjs/idx/authenticator/OktaVerifyTotp.js +9 -1
- package/cjs/idx/authenticator/OktaVerifyTotp.js.map +1 -1
- package/cjs/idx/authenticator/SecurityQuestionEnrollment.js +14 -1
- package/cjs/idx/authenticator/SecurityQuestionEnrollment.js.map +1 -1
- package/cjs/idx/authenticator/SecurityQuestionVerification.js +9 -1
- package/cjs/idx/authenticator/SecurityQuestionVerification.js.map +1 -1
- package/cjs/idx/authenticator/VerificationCodeAuthenticator.js +13 -3
- package/cjs/idx/authenticator/VerificationCodeAuthenticator.js.map +1 -1
- package/cjs/idx/authenticator/WebauthnEnrollment.js +5 -0
- package/cjs/idx/authenticator/WebauthnEnrollment.js.map +1 -1
- package/cjs/idx/authenticator/WebauthnVerification.js +5 -0
- package/cjs/idx/authenticator/WebauthnVerification.js.map +1 -1
- package/cjs/idx/authenticator/util.js +64 -0
- package/cjs/idx/authenticator/util.js.map +1 -0
- package/cjs/idx/idx-js/index.js +0 -122
- package/cjs/idx/idx-js/index.js.map +1 -1
- package/cjs/idx/idx-js/introspect.js +10 -6
- package/cjs/idx/idx-js/introspect.js.map +1 -1
- package/cjs/idx/idx-js/v1/generateIdxAction.js +17 -23
- package/cjs/idx/idx-js/v1/generateIdxAction.js.map +1 -1
- package/cjs/idx/idx-js/v1/makeIdxState.js +5 -4
- package/cjs/idx/idx-js/v1/makeIdxState.js.map +1 -1
- package/cjs/idx/introspect.js +13 -3
- package/cjs/idx/introspect.js.map +1 -1
- package/cjs/idx/proceed.js +14 -11
- package/cjs/idx/proceed.js.map +1 -1
- package/cjs/idx/remediate.js +68 -77
- package/cjs/idx/remediate.js.map +1 -1
- package/cjs/idx/remediators/AuthenticatorEnrollmentData.js +6 -2
- package/cjs/idx/remediators/AuthenticatorEnrollmentData.js.map +1 -1
- package/cjs/idx/remediators/AuthenticatorVerificationData.js +56 -15
- package/cjs/idx/remediators/AuthenticatorVerificationData.js.map +1 -1
- package/cjs/idx/remediators/Base/AuthenticatorData.js +22 -14
- package/cjs/idx/remediators/Base/AuthenticatorData.js.map +1 -1
- package/cjs/idx/remediators/Base/Remediator.js +85 -85
- package/cjs/idx/remediators/Base/Remediator.js.map +1 -1
- package/cjs/idx/remediators/Base/SelectAuthenticator.js +24 -15
- package/cjs/idx/remediators/Base/SelectAuthenticator.js.map +1 -1
- package/cjs/idx/remediators/Base/VerifyAuthenticator.js +15 -4
- package/cjs/idx/remediators/Base/VerifyAuthenticator.js.map +1 -1
- package/cjs/idx/remediators/ChallengePoll.js +8 -1
- package/cjs/idx/remediators/ChallengePoll.js.map +1 -1
- package/cjs/idx/remediators/EnrollPoll.js +1 -1
- package/cjs/idx/remediators/EnrollPoll.js.map +1 -1
- package/cjs/idx/remediators/EnrollProfile.js +15 -9
- package/cjs/idx/remediators/EnrollProfile.js.map +1 -1
- package/cjs/idx/remediators/EnrollmentChannelData.js +0 -8
- package/cjs/idx/remediators/EnrollmentChannelData.js.map +1 -1
- package/cjs/idx/remediators/Identify.js +12 -5
- package/cjs/idx/remediators/Identify.js.map +1 -1
- package/cjs/idx/remediators/ReEnrollAuthenticator.js +9 -8
- package/cjs/idx/remediators/ReEnrollAuthenticator.js.map +1 -1
- package/cjs/idx/remediators/SelectAuthenticatorAuthenticate.js +4 -3
- package/cjs/idx/remediators/SelectAuthenticatorAuthenticate.js.map +1 -1
- package/cjs/idx/remediators/SelectAuthenticatorUnlockAccount.js +0 -1
- package/cjs/idx/remediators/SelectAuthenticatorUnlockAccount.js.map +1 -1
- package/cjs/idx/remediators/Skip.js +1 -8
- package/cjs/idx/remediators/Skip.js.map +1 -1
- package/cjs/idx/remediators/util.js.map +1 -1
- package/cjs/idx/run.js +270 -195
- package/cjs/idx/run.js.map +1 -1
- package/cjs/idx/types/idx-js.js.map +1 -1
- package/cjs/idx/types/index.js +37 -0
- package/cjs/idx/types/index.js.map +1 -1
- package/cjs/idx/util.js +198 -0
- package/cjs/idx/util.js.map +1 -0
- package/cjs/options/browser.js +86 -0
- package/cjs/options/browser.js.map +1 -0
- package/cjs/options/index.js +94 -0
- package/cjs/options/index.js.map +1 -0
- package/cjs/options/node.js +45 -0
- package/cjs/options/node.js.map +1 -0
- package/cjs/options.js +11 -1
- package/cjs/options.js.map +1 -1
- package/cjs/server/serverStorage.js +7 -4
- package/cjs/server/serverStorage.js.map +1 -1
- package/cjs/services/AutoRenewService.js +94 -0
- package/cjs/services/AutoRenewService.js.map +1 -0
- package/cjs/services/SyncStorageService.js +93 -0
- package/cjs/services/SyncStorageService.js.map +1 -0
- package/cjs/services/index.js +30 -0
- package/cjs/services/index.js.map +1 -0
- package/cjs/types/Service.js +2 -0
- package/cjs/types/Service.js.map +1 -0
- package/cjs/types/index.js +13 -0
- package/cjs/types/index.js.map +1 -1
- package/dist/okta-auth-js.min.js +1 -1
- package/dist/okta-auth-js.min.js.LICENSE.txt +0 -8
- package/dist/okta-auth-js.min.js.map +1 -1
- package/dist/okta-auth-js.umd.js +1 -1
- package/dist/okta-auth-js.umd.js.LICENSE.txt +1 -7
- package/dist/okta-auth-js.umd.js.map +1 -1
- package/esm/{index.js → esm.browser.js} +2144 -2975
- package/esm/esm.browser.js.map +1 -0
- package/esm/esm.node.mjs +9595 -0
- package/esm/esm.node.mjs.map +1 -0
- package/lib/AuthStateManager.d.ts +3 -3
- package/lib/OktaAuth.d.ts +5 -4
- package/lib/PromiseQueue.d.ts +6 -2
- package/lib/ServiceManager.d.ts +38 -0
- package/lib/TokenManager.d.ts +0 -1
- package/lib/TransactionManager.d.ts +3 -4
- package/lib/idx/authenticator/Authenticator.d.ts +1 -1
- package/lib/idx/authenticator/OktaPassword.d.ts +2 -1
- package/lib/idx/authenticator/OktaVerifyTotp.d.ts +1 -1
- package/lib/idx/authenticator/SecurityQuestionEnrollment.d.ts +3 -5
- package/lib/idx/authenticator/SecurityQuestionVerification.d.ts +1 -1
- package/lib/idx/authenticator/VerificationCodeAuthenticator.d.ts +2 -1
- package/lib/idx/authenticator/WebauthnEnrollment.d.ts +1 -1
- package/lib/idx/authenticator/WebauthnVerification.d.ts +1 -1
- package/lib/idx/authenticator/util.d.ts +4 -0
- package/lib/idx/idx-js/index.d.ts +1 -17
- package/lib/idx/idx-js/introspect.d.ts +2 -1
- package/lib/idx/idx-js/v1/generateIdxAction.d.ts +1 -1
- package/lib/idx/idx-js/v1/makeIdxState.d.ts +2 -2
- package/lib/idx/proceed.d.ts +1 -3
- package/lib/idx/remediate.d.ts +2 -2
- package/lib/idx/remediators/AuthenticatorVerificationData.d.ts +6 -5
- package/lib/idx/remediators/Base/AuthenticatorData.d.ts +5 -9
- package/lib/idx/remediators/Base/Remediator.d.ts +5 -4
- package/lib/idx/remediators/Base/SelectAuthenticator.d.ts +7 -9
- package/lib/idx/remediators/Base/VerifyAuthenticator.d.ts +2 -4
- package/lib/idx/remediators/ChallengePoll.d.ts +1 -0
- package/lib/idx/remediators/EnrollProfile.d.ts +0 -3
- package/lib/idx/remediators/EnrollmentChannelData.d.ts +0 -4
- package/lib/idx/remediators/Identify.d.ts +3 -5
- package/lib/idx/remediators/ReEnrollAuthenticator.d.ts +2 -5
- package/lib/idx/remediators/SelectAuthenticatorAuthenticate.d.ts +2 -1
- package/lib/idx/remediators/SelectAuthenticatorUnlockAccount.d.ts +1 -2
- package/lib/idx/remediators/Skip.d.ts +0 -3
- package/lib/idx/types/idx-js.d.ts +5 -1
- package/lib/idx/types/index.d.ts +7 -3
- package/lib/idx/util.d.ts +11 -0
- package/lib/options/browser.d.ts +16 -0
- package/lib/options/index.d.ts +14 -0
- package/lib/options/node.d.ts +16 -0
- package/lib/services/AutoRenewService.d.ts +27 -0
- package/lib/services/{TokenService.d.ts → SyncStorageService.d.ts} +8 -5
- package/lib/services/index.d.ts +13 -0
- package/lib/types/OktaAuthOptions.d.ts +5 -0
- package/lib/types/Service.d.ts +23 -0
- package/lib/types/Storage.d.ts +7 -5
- package/lib/types/api.d.ts +6 -5
- package/lib/types/index.d.ts +1 -0
- package/package.json +26 -11
- package/cjs/services/TokenService.js +0 -111
- package/cjs/services/TokenService.js.map +0 -1
- package/esm/index.js.map +0 -1
|
@@ -76,6 +76,7 @@ export interface IdxAuthenticator {
|
|
|
76
76
|
challengeData?: ChallengeData;
|
|
77
77
|
};
|
|
78
78
|
credentialId?: string;
|
|
79
|
+
enrollmentId?: string;
|
|
79
80
|
}
|
|
80
81
|
export interface IdxForm {
|
|
81
82
|
value: IdxRemediationValue[];
|
|
@@ -179,10 +180,12 @@ export interface RawIdxResponse {
|
|
|
179
180
|
value: IdxRemediation[];
|
|
180
181
|
};
|
|
181
182
|
messages?: IdxMessages;
|
|
183
|
+
success?: boolean;
|
|
184
|
+
successWithInteractionCode?: IdxRemediation;
|
|
182
185
|
}
|
|
183
186
|
export declare function isRawIdxResponse(obj: any): obj is RawIdxResponse;
|
|
184
187
|
export interface IdxActions {
|
|
185
|
-
[key: string]:
|
|
188
|
+
[key: string]: () => Promise<IdxResponse>;
|
|
186
189
|
}
|
|
187
190
|
export interface IdxResponse {
|
|
188
191
|
proceed: (remediationName: string, params: unknown) => Promise<IdxResponse>;
|
|
@@ -194,5 +197,6 @@ export interface IdxResponse {
|
|
|
194
197
|
interactionHandle?: string;
|
|
195
198
|
};
|
|
196
199
|
context?: IdxContext;
|
|
200
|
+
requestDidSucceed?: boolean;
|
|
197
201
|
}
|
|
198
202
|
export declare function isIdxResponse(obj: any): obj is IdxResponse;
|
package/lib/idx/types/index.d.ts
CHANGED
|
@@ -15,13 +15,14 @@ import { APIError, Tokens } from '../../types';
|
|
|
15
15
|
import { PKCETransactionMeta } from '../../types/Transaction';
|
|
16
16
|
import { IdxActions, IdxAuthenticator, IdxContext, IdxForm, IdxMessage, IdxOption, IdxRemediation, IdxResponse, RawIdxResponse } from './idx-js';
|
|
17
17
|
import { FlowIdentifier } from './FlowIdentifier';
|
|
18
|
-
export { IdxMessage, ChallengeData, ActivationData } from './idx-js';
|
|
18
|
+
export { IdxMessage, IdxMessages, ChallengeData, ActivationData, IdxResponse, IdxContext, RawIdxResponse } from './idx-js';
|
|
19
19
|
export { AuthenticationOptions } from '../authenticate';
|
|
20
20
|
export { RegistrationOptions } from '../register';
|
|
21
21
|
export { PasswordRecoveryOptions } from '../recoverPassword';
|
|
22
22
|
export { AccountUnlockOptions } from '../unlockAccount';
|
|
23
23
|
export { ProceedOptions } from '../proceed';
|
|
24
24
|
export { CancelOptions } from '../cancel';
|
|
25
|
+
export { RemediateOptions } from '../remediate';
|
|
25
26
|
export { FlowIdentifier };
|
|
26
27
|
export { IdxAuthenticator };
|
|
27
28
|
export { EmailVerifyCallbackResponse } from '../emailVerify';
|
|
@@ -84,7 +85,7 @@ export interface IdxTransaction {
|
|
|
84
85
|
tokens?: Tokens;
|
|
85
86
|
nextStep?: NextStep;
|
|
86
87
|
messages?: IdxMessage[];
|
|
87
|
-
error?: APIError;
|
|
88
|
+
error?: APIError | IdxResponse;
|
|
88
89
|
meta?: IdxTransactionMeta;
|
|
89
90
|
enabledFeatures?: IdxFeature[];
|
|
90
91
|
availableSteps?: NextStep[];
|
|
@@ -99,13 +100,16 @@ export declare type IdxOptions = InteractOptions & IntrospectOptions & {
|
|
|
99
100
|
flow?: FlowIdentifier;
|
|
100
101
|
exchangeCodeForTokens?: boolean;
|
|
101
102
|
autoRemediate?: boolean;
|
|
103
|
+
step?: string;
|
|
102
104
|
};
|
|
103
105
|
export interface IdxPollOptions {
|
|
104
106
|
required?: boolean;
|
|
105
107
|
refresh?: number;
|
|
106
108
|
}
|
|
107
109
|
export declare type Authenticator = {
|
|
108
|
-
|
|
110
|
+
id?: string;
|
|
111
|
+
key?: string;
|
|
109
112
|
methodType?: string;
|
|
110
113
|
phoneNumber?: string;
|
|
111
114
|
};
|
|
115
|
+
export declare function isAuthenticator(obj: any): obj is Authenticator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RemediationValues } from './remediators';
|
|
2
|
+
import { IdxFeature, NextStep } from './types';
|
|
3
|
+
import { IdxMessage, IdxRemediationValue, IdxResponse } from './types/idx-js';
|
|
4
|
+
export declare function isTerminalResponse(idxResponse: IdxResponse): boolean;
|
|
5
|
+
export declare function canSkipFn(idxResponse: IdxResponse): boolean;
|
|
6
|
+
export declare function canResendFn(idxResponse: IdxResponse): boolean;
|
|
7
|
+
export declare function getMessagesFromIdxRemediationValue(value?: IdxRemediationValue[]): IdxMessage[] | undefined;
|
|
8
|
+
export declare function getMessagesFromResponse(idxResponse: IdxResponse): IdxMessage[];
|
|
9
|
+
export declare function getEnabledFeatures(idxResponse: IdxResponse): IdxFeature[];
|
|
10
|
+
export declare function getAvailableSteps(idxResponse: IdxResponse): NextStep[];
|
|
11
|
+
export declare function filterValuesForRemediation(idxResponse: IdxResponse, values: RemediationValues): RemediationValues;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
import { StorageManagerOptions, OktaAuthOptions, StorageUtil } from '../types';
|
|
13
|
+
export declare function getStorage(): StorageUtil;
|
|
14
|
+
export declare const STORAGE_MANAGER_OPTIONS: StorageManagerOptions;
|
|
15
|
+
export declare const enableSharedStorage = true;
|
|
16
|
+
export declare function getCookieSettings(args: OktaAuthOptions | undefined, isHTTPS: boolean): import("../types").CookieOptions;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
import { OktaAuthOptions } from '../types';
|
|
13
|
+
export declare function getDefaultOptions(): OktaAuthOptions;
|
|
14
|
+
export declare function buildOptions(args?: OktaAuthOptions): OktaAuthOptions;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
import { StorageManagerOptions, OktaAuthOptions, StorageUtil } from '../types';
|
|
13
|
+
export declare function getStorage(): StorageUtil;
|
|
14
|
+
export declare const STORAGE_MANAGER_OPTIONS: StorageManagerOptions;
|
|
15
|
+
export declare const enableSharedStorage = false;
|
|
16
|
+
export declare function getCookieSettings(args?: OktaAuthOptions, isHTTPS?: boolean): import("../types").CookieOptions | undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
import { TokenManager } from '../TokenManager';
|
|
13
|
+
import { ServiceInterface, ServiceManagerOptions } from '../types';
|
|
14
|
+
export declare class AutoRenewService implements ServiceInterface {
|
|
15
|
+
private tokenManager;
|
|
16
|
+
private options;
|
|
17
|
+
private renewTimeQueue;
|
|
18
|
+
private started;
|
|
19
|
+
constructor(tokenManager: TokenManager, options?: ServiceManagerOptions);
|
|
20
|
+
private shouldThrottleRenew;
|
|
21
|
+
requiresLeadership(): boolean;
|
|
22
|
+
private onTokenExpiredHandler;
|
|
23
|
+
canStart(): boolean;
|
|
24
|
+
start(): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
isStarted(): boolean;
|
|
27
|
+
}
|
|
@@ -10,14 +10,17 @@
|
|
|
10
10
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import { TokenManager } from '../TokenManager';
|
|
13
|
-
import {
|
|
14
|
-
export declare class
|
|
13
|
+
import { ServiceManagerOptions, ServiceInterface } from '../types';
|
|
14
|
+
export declare class SyncStorageService implements ServiceInterface {
|
|
15
15
|
private tokenManager;
|
|
16
16
|
private options;
|
|
17
|
-
private storageListener?;
|
|
18
|
-
private onTokenExpiredHandler?;
|
|
19
17
|
private syncTimeout;
|
|
20
|
-
|
|
18
|
+
private started;
|
|
19
|
+
constructor(tokenManager: TokenManager, options?: ServiceManagerOptions);
|
|
20
|
+
private storageListener;
|
|
21
|
+
requiresLeadership(): boolean;
|
|
22
|
+
isStarted(): boolean;
|
|
23
|
+
canStart(): boolean;
|
|
21
24
|
start(): void;
|
|
22
25
|
stop(): void;
|
|
23
26
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
export * from './AutoRenewService';
|
|
13
|
+
export * from './SyncStorageService';
|
|
@@ -15,7 +15,11 @@ import { HttpRequestClient } from './http';
|
|
|
15
15
|
import { AuthState } from './AuthState';
|
|
16
16
|
import { TransactionManagerOptions } from './Transaction';
|
|
17
17
|
import { FlowIdentifier } from '../idx/types';
|
|
18
|
+
import { ServiceManagerOptions } from './Service';
|
|
18
19
|
import OktaAuth from '../OktaAuth';
|
|
20
|
+
export interface IsAuthenticatedOptions {
|
|
21
|
+
onExpiredToken?: 'renew' | 'remove' | 'none';
|
|
22
|
+
}
|
|
19
23
|
export interface TokenManagerOptions {
|
|
20
24
|
autoRenew?: boolean;
|
|
21
25
|
autoRemove?: boolean;
|
|
@@ -59,6 +63,7 @@ export interface OktaAuthOptions extends CustomUrls {
|
|
|
59
63
|
restoreOriginalUri?: (oktaAuth: OktaAuth, originalUri?: string) => Promise<void>;
|
|
60
64
|
devMode?: boolean;
|
|
61
65
|
storageManager?: StorageManagerOptions;
|
|
66
|
+
services?: ServiceManagerOptions;
|
|
62
67
|
transactionManager?: TransactionManagerOptions;
|
|
63
68
|
flow?: FlowIdentifier;
|
|
64
69
|
codeChallenge?: string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface ServiceManagerInterface {
|
|
2
|
+
isLeader(): boolean;
|
|
3
|
+
start(): void;
|
|
4
|
+
stop(): void;
|
|
5
|
+
getService(name: string): ServiceInterface | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface ServiceInterface {
|
|
8
|
+
start(): void;
|
|
9
|
+
stop(): void;
|
|
10
|
+
isStarted(): boolean;
|
|
11
|
+
canStart(): boolean;
|
|
12
|
+
requiresLeadership(): boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface AutoRenewServiceOptions {
|
|
15
|
+
autoRenew?: boolean;
|
|
16
|
+
autoRemove?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface SyncStorageServiceOptions {
|
|
19
|
+
syncStorage?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare type ServiceManagerOptions = AutoRenewServiceOptions & SyncStorageServiceOptions & {
|
|
22
|
+
broadcastChannelName?: string;
|
|
23
|
+
};
|
package/lib/types/Storage.d.ts
CHANGED
|
@@ -40,9 +40,13 @@ export interface TransactionStorage extends StorageProvider {
|
|
|
40
40
|
setStorage(obj: TransactionMeta): void;
|
|
41
41
|
getStorage(): TransactionMeta;
|
|
42
42
|
}
|
|
43
|
+
export interface SavedIdxResponse {
|
|
44
|
+
rawIdxResponse: RawIdxResponse;
|
|
45
|
+
requestDidSucceed?: boolean;
|
|
46
|
+
}
|
|
43
47
|
export interface IdxResponseStorage extends StorageProvider {
|
|
44
|
-
setStorage(obj:
|
|
45
|
-
getStorage():
|
|
48
|
+
setStorage(obj: SavedIdxResponse): void;
|
|
49
|
+
getStorage(): SavedIdxResponse;
|
|
46
50
|
}
|
|
47
51
|
export interface StorageOptions extends CookieOptions {
|
|
48
52
|
storageType?: StorageType;
|
|
@@ -68,9 +72,7 @@ export interface BrowserStorageUtil extends StorageUtil {
|
|
|
68
72
|
getCookieStorage(options?: StorageOptions): CookieStorage;
|
|
69
73
|
testStorage(storage: any): boolean;
|
|
70
74
|
storage: Cookies;
|
|
71
|
-
inMemoryStore:
|
|
72
|
-
string?: string;
|
|
73
|
-
};
|
|
75
|
+
inMemoryStore: Record<string, unknown>;
|
|
74
76
|
getHttpCache(options?: StorageOptions): StorageProvider;
|
|
75
77
|
getPKCEStorage(options?: StorageOptions): PKCEStorage;
|
|
76
78
|
}
|
package/lib/types/api.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { CustomUrls, OktaAuthOptions } from './OktaAuthOptions';
|
|
|
17
17
|
import { StorageManager } from '../StorageManager';
|
|
18
18
|
import TransactionManager from '../TransactionManager';
|
|
19
19
|
import { TokenManagerInterface } from './TokenManager';
|
|
20
|
+
import { ServiceManagerInterface } from './Service';
|
|
20
21
|
import { OktaUserAgent } from '../OktaUserAgent';
|
|
21
22
|
import { AuthenticationOptions, RegistrationOptions as IdxRegistrationOptions, PasswordRecoveryOptions, AccountUnlockOptions, ProceedOptions, CancelOptions, IdxOptions, IdxTransaction, IdxTransactionMeta, EmailVerifyCallbackResponse, IdxAuthenticator, ChallengeData, ActivationData, WebauthnEnrollValues, WebauthnVerificationValues, FlowIdentifier, IdxPollOptions } from '../idx/types';
|
|
22
23
|
import { InteractOptions, InteractResponse } from '../idx/interact';
|
|
@@ -31,6 +32,7 @@ export interface OktaAuthInterface {
|
|
|
31
32
|
storageManager: StorageManager;
|
|
32
33
|
transactionManager: TransactionManager;
|
|
33
34
|
tokenManager: TokenManagerInterface;
|
|
35
|
+
serviceManager: ServiceManagerInterface;
|
|
34
36
|
idx: IdxAPI;
|
|
35
37
|
features: FeaturesAPI;
|
|
36
38
|
token: TokenAPI;
|
|
@@ -180,13 +182,14 @@ export interface SigninOptions extends SupportsCodeFlow, AuthenticationOptions {
|
|
|
180
182
|
deviceToken?: string;
|
|
181
183
|
};
|
|
182
184
|
sendFingerprint?: boolean;
|
|
185
|
+
stateToken?: string;
|
|
183
186
|
}
|
|
184
187
|
export interface SigninWithRedirectOptions extends SigninOptions, TokenParams {
|
|
185
188
|
originalUri?: string;
|
|
186
189
|
}
|
|
187
190
|
export interface SigninWithCredentialsOptions extends SigninOptions {
|
|
188
|
-
username
|
|
189
|
-
password
|
|
191
|
+
username?: string;
|
|
192
|
+
password?: string;
|
|
190
193
|
}
|
|
191
194
|
export interface SigninAPI {
|
|
192
195
|
signIn(opts: SigninOptions): Promise<AuthTransaction>;
|
|
@@ -229,9 +232,7 @@ export interface IdxAPI {
|
|
|
229
232
|
unlockAccount: (options?: AccountUnlockOptions) => Promise<IdxTransaction>;
|
|
230
233
|
poll: (options?: IdxPollOptions) => Promise<IdxTransaction>;
|
|
231
234
|
start: (options?: IdxOptions) => Promise<IdxTransaction>;
|
|
232
|
-
canProceed(options?:
|
|
233
|
-
state?: string;
|
|
234
|
-
}): boolean;
|
|
235
|
+
canProceed(options?: ProceedOptions): boolean;
|
|
235
236
|
proceed: (options?: ProceedOptions) => Promise<IdxTransaction>;
|
|
236
237
|
cancel: (options?: CancelOptions) => Promise<IdxTransaction>;
|
|
237
238
|
getFlow(): FlowIdentifier | undefined;
|
package/lib/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,13 +2,23 @@
|
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@okta/okta-auth-js",
|
|
4
4
|
"description": "The Okta Auth SDK",
|
|
5
|
-
"version": "6.1
|
|
5
|
+
"version": "6.3.1",
|
|
6
6
|
"homepage": "https://github.com/okta/okta-auth-js",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "cjs/index.js",
|
|
9
|
-
"module": "esm/
|
|
9
|
+
"module": "esm/esm.node.mjs",
|
|
10
10
|
"browser": "dist/okta-auth-js.umd.js",
|
|
11
11
|
"types": "lib/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
"node": {
|
|
14
|
+
"import": "./esm/esm.node.mjs",
|
|
15
|
+
"require": "./cjs/index.js"
|
|
16
|
+
},
|
|
17
|
+
"browser": {
|
|
18
|
+
"import": "./esm/esm.browser.js"
|
|
19
|
+
},
|
|
20
|
+
"default": "./dist/okta-auth-js.umd.js"
|
|
21
|
+
},
|
|
12
22
|
"repository": {
|
|
13
23
|
"type": "git",
|
|
14
24
|
"url": "https://github.com/okta/okta-auth-js.git"
|
|
@@ -20,8 +30,9 @@
|
|
|
20
30
|
"banners": "node ./scripts/maintain-banners.js",
|
|
21
31
|
"clean": "yarn clean:build",
|
|
22
32
|
"clean:build": "rimraf build && rimraf build2",
|
|
23
|
-
"dev": "
|
|
24
|
-
"
|
|
33
|
+
"dev:esm": "NODE_ENV=development yarn build:esm --watch",
|
|
34
|
+
"dev:web": "cross-env NODE_ENV=development webpack --config webpack.config.js --watch",
|
|
35
|
+
"lint": "eslint --ext .js,.ts,.jsx .",
|
|
25
36
|
"tsd": "tsd",
|
|
26
37
|
"lint:report": "eslint -f checkstyle -o ./build2/reports/lint/eslint-checkstyle-result.xml .",
|
|
27
38
|
"validate": "yarn tsc --noEmit && yarn lint && yarn workspace @okta/test.app validate && yarn tsd",
|
|
@@ -36,6 +47,9 @@
|
|
|
36
47
|
"test:report": "yarn test --ci --silent || true",
|
|
37
48
|
"test:samples": "yarn workspace @okta/test.e2e.samples start",
|
|
38
49
|
"test:integration": "jest --config ./jest.integration.js",
|
|
50
|
+
"test:bundle:esm:browser": "cross-env BUNDLE_ENV=browser NODE_OPTIONS=--experimental-vm-modules jest --config ./jest.esm.mjs",
|
|
51
|
+
"test:bundle:esm:node": "cross-env BUNDLE_ENV=node NODE_OPTIONS=--experimental-vm-modules jest --config ./jest.esm.mjs",
|
|
52
|
+
"test:bundle:cjs": "cross-env BUNDLE_ENV=node jest --config ./jest.cjs.js",
|
|
39
53
|
"build": "node scripts/build.js",
|
|
40
54
|
"build:cdn": "cross-env NODE_ENV=production webpack --config webpack.cdn.config.js",
|
|
41
55
|
"build:web": "cross-env NODE_ENV=production webpack --config webpack.config.js",
|
|
@@ -74,10 +88,11 @@
|
|
|
74
88
|
"@peculiar/webcrypto": "1.1.6",
|
|
75
89
|
"Base64": "1.1.0",
|
|
76
90
|
"atob": "^2.1.2",
|
|
91
|
+
"broadcast-channel": "^4.10.0",
|
|
77
92
|
"btoa": "^1.2.1",
|
|
78
93
|
"core-js": "^3.6.5",
|
|
79
94
|
"cross-fetch": "^3.1.5",
|
|
80
|
-
"js-cookie": "
|
|
95
|
+
"js-cookie": "^3.0.1",
|
|
81
96
|
"jsonpath-plus": "^6.0.1",
|
|
82
97
|
"node-cache": "^5.1.2",
|
|
83
98
|
"p-cancelable": "^2.0.0",
|
|
@@ -99,7 +114,7 @@
|
|
|
99
114
|
"@rollup/plugin-alias": "^3.1.8",
|
|
100
115
|
"@rollup/plugin-babel": "^5.3.0",
|
|
101
116
|
"@rollup/plugin-replace": "^3.0.0",
|
|
102
|
-
"@types/jest": "^
|
|
117
|
+
"@types/jest": "^27.4.0",
|
|
103
118
|
"@types/node": "^14.0.3",
|
|
104
119
|
"@typescript-eslint/eslint-plugin": "^2.34.0",
|
|
105
120
|
"@typescript-eslint/parser": "^2.34.0",
|
|
@@ -119,7 +134,7 @@
|
|
|
119
134
|
"globby": "^6.1.0",
|
|
120
135
|
"istanbul-instrumenter-loader": "^3.0.1",
|
|
121
136
|
"jasmine-ajax": "^4.0.0",
|
|
122
|
-
"jest": "^
|
|
137
|
+
"jest": "^27.5.1",
|
|
123
138
|
"jest-junit": "^9.0.0",
|
|
124
139
|
"json-loader": "0.5.4",
|
|
125
140
|
"lodash": "4.17.20",
|
|
@@ -128,7 +143,7 @@
|
|
|
128
143
|
"rollup-plugin-license": "^2.6.0",
|
|
129
144
|
"rollup-plugin-typescript2": "^0.30.0",
|
|
130
145
|
"shelljs": "0.8.4",
|
|
131
|
-
"ts-jest": "^
|
|
146
|
+
"ts-jest": "^27.1.3",
|
|
132
147
|
"ts-loader": "^9.2.6",
|
|
133
148
|
"tsd": "^0.17.0",
|
|
134
149
|
"typescript": "^4.2.3",
|
|
@@ -172,8 +187,8 @@
|
|
|
172
187
|
}
|
|
173
188
|
},
|
|
174
189
|
"okta": {
|
|
175
|
-
"commitSha": "
|
|
176
|
-
"fullVersion": "6.1
|
|
177
|
-
"testedSha": "
|
|
190
|
+
"commitSha": "9c47e4474ff9b450844f599b8801569269e5b417",
|
|
191
|
+
"fullVersion": "6.3.1-g9c47e44",
|
|
192
|
+
"testedSha": "4295de6928d73ba8dade782e3c2ad80f1d21798a"
|
|
178
193
|
}
|
|
179
194
|
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.TokenService = void 0;
|
|
4
|
-
|
|
5
|
-
var _TokenManager = require("../TokenManager");
|
|
6
|
-
|
|
7
|
-
var _errors = require("../errors");
|
|
8
|
-
|
|
9
|
-
var _features = require("../features");
|
|
10
|
-
|
|
11
|
-
/*!
|
|
12
|
-
* Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
13
|
-
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
14
|
-
*
|
|
15
|
-
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
18
|
-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
-
*
|
|
20
|
-
* See the License for the specific language governing permissions and limitations under the License.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/* global window */
|
|
24
|
-
function shouldThrottleRenew(renewTimeQueue) {
|
|
25
|
-
let res = false;
|
|
26
|
-
renewTimeQueue.push(Date.now());
|
|
27
|
-
|
|
28
|
-
if (renewTimeQueue.length >= 10) {
|
|
29
|
-
// get and remove first item from queue
|
|
30
|
-
const firstTime = renewTimeQueue.shift();
|
|
31
|
-
const lastTime = renewTimeQueue[renewTimeQueue.length - 1];
|
|
32
|
-
res = lastTime - firstTime < 30 * 1000;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return res;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
class TokenService {
|
|
39
|
-
constructor(tokenManager, options = {}) {
|
|
40
|
-
this.tokenManager = tokenManager;
|
|
41
|
-
this.options = options;
|
|
42
|
-
this.storageListener = undefined;
|
|
43
|
-
this.onTokenExpiredHandler = undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
start() {
|
|
47
|
-
const renewTimeQueue = [];
|
|
48
|
-
|
|
49
|
-
this.onTokenExpiredHandler = key => {
|
|
50
|
-
if (this.options.autoRenew) {
|
|
51
|
-
if (shouldThrottleRenew(renewTimeQueue)) {
|
|
52
|
-
const error = new _errors.AuthSdkError('Too many token renew requests');
|
|
53
|
-
this.tokenManager.emitError(error);
|
|
54
|
-
} else {
|
|
55
|
-
this.tokenManager.renew(key).catch(() => {}); // Renew errors will emit an "error" event
|
|
56
|
-
}
|
|
57
|
-
} else if (this.options.autoRemove) {
|
|
58
|
-
this.tokenManager.remove(key);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
this.tokenManager.on(_TokenManager.EVENT_EXPIRED, this.onTokenExpiredHandler);
|
|
63
|
-
this.tokenManager.setExpireEventTimeoutAll();
|
|
64
|
-
|
|
65
|
-
if (this.options.syncStorage && (0, _features.isBrowser)()) {
|
|
66
|
-
// Sync authState cross multiple tabs when localStorage is used as the storageProvider
|
|
67
|
-
// A StorageEvent is sent to a window when a storage area it has access to is changed
|
|
68
|
-
// within the context of another document.
|
|
69
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/StorageEvent
|
|
70
|
-
this.storageListener = ({
|
|
71
|
-
key,
|
|
72
|
-
newValue,
|
|
73
|
-
oldValue
|
|
74
|
-
}) => {
|
|
75
|
-
const handleCrossTabsStorageChange = () => {
|
|
76
|
-
this.tokenManager.resetExpireEventTimeoutAll();
|
|
77
|
-
this.tokenManager.emitEventsForCrossTabsStorageUpdate(newValue, oldValue);
|
|
78
|
-
}; // Skip if:
|
|
79
|
-
// not from localStorage.clear (event.key is null)
|
|
80
|
-
// event.key is not the storageKey
|
|
81
|
-
// oldValue === newValue
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (key && (key !== this.options.storageKey || newValue === oldValue)) {
|
|
85
|
-
return;
|
|
86
|
-
} // LocalStorage cross tabs update is not synced in IE, set a 1s timer by default to read latest value
|
|
87
|
-
// https://stackoverflow.com/questions/24077117/localstorage-in-win8-1-ie11-does-not-synchronize
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.syncTimeout = setTimeout(() => handleCrossTabsStorageChange(), this.options._storageEventDelay);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
window.addEventListener('storage', this.storageListener);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
stop() {
|
|
98
|
-
this.tokenManager.clearExpireEventTimeoutAll();
|
|
99
|
-
this.tokenManager.off(_TokenManager.EVENT_EXPIRED, this.onTokenExpiredHandler);
|
|
100
|
-
|
|
101
|
-
if (this.options.syncStorage && (0, _features.isBrowser)()) {
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
103
|
-
window.removeEventListener('storage', this.storageListener);
|
|
104
|
-
clearTimeout(this.syncTimeout);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
exports.TokenService = TokenService;
|
|
111
|
-
//# sourceMappingURL=TokenService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/services/TokenService.ts"],"names":["shouldThrottleRenew","renewTimeQueue","res","push","Date","now","length","firstTime","shift","lastTime","TokenService","constructor","tokenManager","options","storageListener","undefined","onTokenExpiredHandler","start","key","autoRenew","error","AuthSdkError","emitError","renew","catch","autoRemove","remove","on","EVENT_EXPIRED","setExpireEventTimeoutAll","syncStorage","newValue","oldValue","handleCrossTabsStorageChange","resetExpireEventTimeoutAll","emitEventsForCrossTabsStorageUpdate","storageKey","syncTimeout","setTimeout","_storageEventDelay","window","addEventListener","stop","clearExpireEventTimeoutAll","off","removeEventListener","clearTimeout"],"mappings":"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","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n\n/* global window */\nimport { TokenManager, EVENT_EXPIRED } from '../TokenManager';\nimport { AuthSdkError } from '../errors';\nimport { isBrowser } from '../features';\nimport { TokenManagerOptions } from '../types';\n\nfunction shouldThrottleRenew(renewTimeQueue) {\n let res = false;\n renewTimeQueue.push(Date.now());\n if (renewTimeQueue.length >= 10) {\n // get and remove first item from queue\n const firstTime = renewTimeQueue.shift();\n const lastTime = renewTimeQueue[renewTimeQueue.length - 1];\n res = lastTime - firstTime < 30 * 1000;\n }\n return res;\n}\n\nexport class TokenService {\n private tokenManager: TokenManager;\n private options: TokenManagerOptions;\n private storageListener?: (event: StorageEvent) => void;\n private onTokenExpiredHandler?: (key: string) => void;\n private syncTimeout: unknown;\n\n constructor(tokenManager: TokenManager, options: TokenManagerOptions = {}) {\n this.tokenManager = tokenManager;\n this.options = options;\n this.storageListener = undefined;\n this.onTokenExpiredHandler = undefined;\n }\n\n start() {\n const renewTimeQueue = [];\n this.onTokenExpiredHandler = (key) => {\n if (this.options.autoRenew) {\n if (shouldThrottleRenew(renewTimeQueue)) {\n const error = new AuthSdkError('Too many token renew requests');\n this.tokenManager.emitError(error);\n } else {\n this.tokenManager.renew(key).catch(() => {}); // Renew errors will emit an \"error\" event \n }\n } else if (this.options.autoRemove) {\n this.tokenManager.remove(key);\n }\n };\n this.tokenManager.on(EVENT_EXPIRED, this.onTokenExpiredHandler);\n\n this.tokenManager.setExpireEventTimeoutAll();\n\n if (this.options.syncStorage && isBrowser()) {\n // Sync authState cross multiple tabs when localStorage is used as the storageProvider\n // A StorageEvent is sent to a window when a storage area it has access to is changed \n // within the context of another document.\n // https://developer.mozilla.org/en-US/docs/Web/API/StorageEvent\n\n this.storageListener = ({ key, newValue, oldValue }: StorageEvent) => {\n const handleCrossTabsStorageChange = () => {\n this.tokenManager.resetExpireEventTimeoutAll();\n this.tokenManager.emitEventsForCrossTabsStorageUpdate(newValue, oldValue);\n };\n\n // Skip if:\n // not from localStorage.clear (event.key is null)\n // event.key is not the storageKey\n // oldValue === newValue\n if (key && (key !== this.options.storageKey || newValue === oldValue)) {\n return;\n }\n\n // LocalStorage cross tabs update is not synced in IE, set a 1s timer by default to read latest value\n // https://stackoverflow.com/questions/24077117/localstorage-in-win8-1-ie11-does-not-synchronize\n this.syncTimeout = setTimeout(() => handleCrossTabsStorageChange(), this.options._storageEventDelay);\n };\n\n window.addEventListener('storage', this.storageListener);\n }\n }\n\n stop() {\n this.tokenManager.clearExpireEventTimeoutAll();\n this.tokenManager.off(EVENT_EXPIRED, this.onTokenExpiredHandler);\n if (this.options.syncStorage && isBrowser()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n window.removeEventListener('storage', this.storageListener!);\n clearTimeout(this.syncTimeout as any);\n }\n }\n}"],"file":"TokenService.js"}
|