@auth0/auth0-spa-js 2.19.0 → 2.19.2
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/auth0-spa-js.development.js +47 -26
- package/dist/auth0-spa-js.development.js.map +1 -1
- package/dist/auth0-spa-js.production.esm.js +1 -1
- package/dist/auth0-spa-js.production.esm.js.map +1 -1
- package/dist/auth0-spa-js.production.js +1 -1
- package/dist/auth0-spa-js.production.js.map +1 -1
- package/dist/auth0-spa-js.worker.development.js +7 -0
- package/dist/auth0-spa-js.worker.development.js.map +1 -1
- package/dist/auth0-spa-js.worker.production.js +1 -1
- package/dist/auth0-spa-js.worker.production.js.map +1 -1
- package/dist/lib/auth0-spa-js.cjs.js +47 -26
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/dist/typings/Auth0Client.d.ts +476 -476
- package/dist/typings/Auth0Client.utils.d.ts +90 -90
- package/dist/typings/MyAccountApiClient.d.ts +92 -92
- package/dist/typings/TokenExchange.d.ts +77 -77
- package/dist/typings/api.d.ts +33 -33
- package/dist/typings/cache/cache-localstorage.d.ts +7 -7
- package/dist/typings/cache/cache-manager.d.ts +69 -69
- package/dist/typings/cache/cache-memory.d.ts +4 -4
- package/dist/typings/cache/index.d.ts +4 -4
- package/dist/typings/cache/key-manifest.d.ts +12 -12
- package/dist/typings/cache/shared.d.ts +68 -68
- package/dist/typings/constants.d.ts +58 -58
- package/dist/typings/dpop/dpop.d.ts +17 -17
- package/dist/typings/dpop/storage.d.ts +27 -27
- package/dist/typings/dpop/utils.d.ts +15 -15
- package/dist/typings/errors.d.ts +96 -96
- package/dist/typings/fetcher.d.ts +54 -54
- package/dist/typings/global.d.ts +826 -826
- package/dist/typings/http.d.ts +11 -11
- package/dist/typings/index.d.ts +24 -24
- package/dist/typings/jwt.d.ts +21 -21
- package/dist/typings/lock.d.ts +32 -32
- package/dist/typings/mfa/MfaApiClient.d.ts +225 -225
- package/dist/typings/mfa/MfaContextManager.d.ts +79 -79
- package/dist/typings/mfa/constants.d.ts +23 -23
- package/dist/typings/mfa/errors.d.ts +117 -117
- package/dist/typings/mfa/index.d.ts +4 -4
- package/dist/typings/mfa/types.d.ts +181 -181
- package/dist/typings/mfa/utils.d.ts +23 -23
- package/dist/typings/promise-utils.d.ts +2 -2
- package/dist/typings/scope.d.ts +35 -35
- package/dist/typings/storage.d.ts +26 -26
- package/dist/typings/transaction-manager.d.ts +33 -33
- package/dist/typings/utils.d.ts +36 -36
- package/dist/typings/version.d.ts +2 -2
- package/dist/typings/worker/token.worker.d.ts +1 -1
- package/dist/typings/worker/worker.types.d.ts +30 -27
- package/dist/typings/worker/worker.utils.d.ts +13 -13
- package/package.json +1 -1
- package/src/Auth0Client.ts +10 -0
- package/src/api.ts +15 -11
- package/src/cache/cache-manager.ts +28 -9
- package/src/version.ts +1 -1
- package/src/worker/token.worker.ts +6 -0
- package/src/worker/worker.types.ts +6 -1
- package/src/worker/worker.utils.ts +5 -1
package/dist/typings/utils.d.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { AuthenticationResult, PopupConfigOptions } from './global';
|
|
2
|
-
export declare const parseAuthenticationResult: (queryString: string) => AuthenticationResult;
|
|
3
|
-
export declare const runIframe: (authorizeUrl: string, eventOrigin: string, timeoutInSeconds?: number) => Promise<AuthenticationResult>;
|
|
4
|
-
export declare const openPopup: (url: string) => Window | null;
|
|
5
|
-
export declare const runPopup: (config: PopupConfigOptions, eventOrigin: string) => Promise<AuthenticationResult>;
|
|
6
|
-
export declare const getCrypto: () => Crypto;
|
|
7
|
-
export declare const createRandomString: () => string;
|
|
8
|
-
export declare const encode: (value: string) => string;
|
|
9
|
-
export declare const decode: (value: string) => string;
|
|
10
|
-
/**
|
|
11
|
-
* Strips any property that is not present in ALLOWED_AUTH0CLIENT_PROPERTIES
|
|
12
|
-
* @param auth0Client - The full auth0Client object
|
|
13
|
-
* @param excludeEnv - If true, excludes the 'env' property from the result
|
|
14
|
-
* @returns The stripped auth0Client object
|
|
15
|
-
*/
|
|
16
|
-
export declare const stripAuth0Client: (auth0Client: any, excludeEnv?: boolean) => any;
|
|
17
|
-
export declare const createQueryParams: ({ clientId: client_id, ...params }: any) => string;
|
|
18
|
-
export declare const sha256: (s: string) => Promise<any>;
|
|
19
|
-
export declare const urlDecodeB64: (input: string) => string;
|
|
20
|
-
export declare const bufferToBase64UrlEncoded: (input: number[] | Uint8Array) => string;
|
|
21
|
-
export declare const validateCrypto: () => void;
|
|
22
|
-
/**
|
|
23
|
-
* @ignore
|
|
24
|
-
*/
|
|
25
|
-
export declare const getDomain: (domainUrl: string) => string;
|
|
26
|
-
/**
|
|
27
|
-
* @ignore
|
|
28
|
-
*/
|
|
29
|
-
export declare const getTokenIssuer: (issuer: string | undefined, domainUrl: string) => string;
|
|
30
|
-
export declare const parseNumber: (value: any) => number | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Ponyfill for `Object.fromEntries()`, which is not available until ES2020.
|
|
33
|
-
*
|
|
34
|
-
* When the target of this project reaches ES2020, this can be removed.
|
|
35
|
-
*/
|
|
36
|
-
export declare const fromEntries: <T = any>(iterable: Iterable<[PropertyKey, T]>) => Record<PropertyKey, T>;
|
|
1
|
+
import { AuthenticationResult, PopupConfigOptions } from './global';
|
|
2
|
+
export declare const parseAuthenticationResult: (queryString: string) => AuthenticationResult;
|
|
3
|
+
export declare const runIframe: (authorizeUrl: string, eventOrigin: string, timeoutInSeconds?: number) => Promise<AuthenticationResult>;
|
|
4
|
+
export declare const openPopup: (url: string) => Window | null;
|
|
5
|
+
export declare const runPopup: (config: PopupConfigOptions, eventOrigin: string) => Promise<AuthenticationResult>;
|
|
6
|
+
export declare const getCrypto: () => Crypto;
|
|
7
|
+
export declare const createRandomString: () => string;
|
|
8
|
+
export declare const encode: (value: string) => string;
|
|
9
|
+
export declare const decode: (value: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Strips any property that is not present in ALLOWED_AUTH0CLIENT_PROPERTIES
|
|
12
|
+
* @param auth0Client - The full auth0Client object
|
|
13
|
+
* @param excludeEnv - If true, excludes the 'env' property from the result
|
|
14
|
+
* @returns The stripped auth0Client object
|
|
15
|
+
*/
|
|
16
|
+
export declare const stripAuth0Client: (auth0Client: any, excludeEnv?: boolean) => any;
|
|
17
|
+
export declare const createQueryParams: ({ clientId: client_id, ...params }: any) => string;
|
|
18
|
+
export declare const sha256: (s: string) => Promise<any>;
|
|
19
|
+
export declare const urlDecodeB64: (input: string) => string;
|
|
20
|
+
export declare const bufferToBase64UrlEncoded: (input: number[] | Uint8Array) => string;
|
|
21
|
+
export declare const validateCrypto: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* @ignore
|
|
24
|
+
*/
|
|
25
|
+
export declare const getDomain: (domainUrl: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
29
|
+
export declare const getTokenIssuer: (issuer: string | undefined, domainUrl: string) => string;
|
|
30
|
+
export declare const parseNumber: (value: any) => number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Ponyfill for `Object.fromEntries()`, which is not available until ES2020.
|
|
33
|
+
*
|
|
34
|
+
* When the target of this project reaches ES2020, this can be removed.
|
|
35
|
+
*/
|
|
36
|
+
export declare const fromEntries: <T = any>(iterable: Iterable<[PropertyKey, T]>) => Record<PropertyKey, T>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "2.19.
|
|
2
|
-
export default _default;
|
|
1
|
+
declare const _default: "2.19.2";
|
|
2
|
+
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import { FetchOptions } from '../global';
|
|
2
|
-
export type WorkerInitMessage = {
|
|
3
|
-
type: 'init';
|
|
4
|
-
allowedBaseUrl: string;
|
|
5
|
-
};
|
|
6
|
-
type WorkerTokenMessage = {
|
|
7
|
-
timeout: number;
|
|
8
|
-
fetchUrl: string;
|
|
9
|
-
fetchOptions: FetchOptions;
|
|
10
|
-
useFormData?: boolean;
|
|
11
|
-
auth: {
|
|
12
|
-
audience: string;
|
|
13
|
-
scope: string;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export type WorkerRefreshTokenMessage = WorkerTokenMessage & {
|
|
17
|
-
type: 'refresh';
|
|
18
|
-
useMrrt?: boolean;
|
|
19
|
-
};
|
|
20
|
-
export type WorkerRevokeTokenMessage = Omit<WorkerTokenMessage, 'auth'> & {
|
|
21
|
-
type: 'revoke';
|
|
22
|
-
auth: {
|
|
23
|
-
audience: string;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
export type
|
|
27
|
-
|
|
1
|
+
import { FetchOptions } from '../global';
|
|
2
|
+
export type WorkerInitMessage = {
|
|
3
|
+
type: 'init';
|
|
4
|
+
allowedBaseUrl: string;
|
|
5
|
+
};
|
|
6
|
+
type WorkerTokenMessage = {
|
|
7
|
+
timeout: number;
|
|
8
|
+
fetchUrl: string;
|
|
9
|
+
fetchOptions: FetchOptions;
|
|
10
|
+
useFormData?: boolean;
|
|
11
|
+
auth: {
|
|
12
|
+
audience: string;
|
|
13
|
+
scope: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type WorkerRefreshTokenMessage = WorkerTokenMessage & {
|
|
17
|
+
type: 'refresh';
|
|
18
|
+
useMrrt?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type WorkerRevokeTokenMessage = Omit<WorkerTokenMessage, 'auth'> & {
|
|
21
|
+
type: 'revoke';
|
|
22
|
+
auth: {
|
|
23
|
+
audience: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type WorkerClearMessage = {
|
|
27
|
+
type: 'clear';
|
|
28
|
+
};
|
|
29
|
+
export type WorkerMessage = WorkerInitMessage | WorkerRefreshTokenMessage | WorkerRevokeTokenMessage | WorkerClearMessage;
|
|
30
|
+
export {};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { WorkerRefreshTokenMessage, WorkerRevokeTokenMessage } from './worker.types';
|
|
2
|
-
/**
|
|
3
|
-
* Sends a message to a Web Worker and returns a Promise that resolves with
|
|
4
|
-
* the worker's response, or rejects if the worker replies with an error.
|
|
5
|
-
*
|
|
6
|
-
* Uses a {@link MessageChannel} so each call gets its own private reply port,
|
|
7
|
-
* making concurrent calls safe without shared state.
|
|
8
|
-
*
|
|
9
|
-
* @param message - The typed message to send (`refresh` or `revoke`).
|
|
10
|
-
* @param to - The target {@link Worker} instance.
|
|
11
|
-
* @returns A Promise that resolves with the worker's response payload.
|
|
12
|
-
*/
|
|
13
|
-
export declare const sendMessage: <T = any>(message: WorkerRefreshTokenMessage | WorkerRevokeTokenMessage, to: Worker) => Promise<T>;
|
|
1
|
+
import { WorkerClearMessage, WorkerRefreshTokenMessage, WorkerRevokeTokenMessage } from './worker.types';
|
|
2
|
+
/**
|
|
3
|
+
* Sends a message to a Web Worker and returns a Promise that resolves with
|
|
4
|
+
* the worker's response, or rejects if the worker replies with an error.
|
|
5
|
+
*
|
|
6
|
+
* Uses a {@link MessageChannel} so each call gets its own private reply port,
|
|
7
|
+
* making concurrent calls safe without shared state.
|
|
8
|
+
*
|
|
9
|
+
* @param message - The typed message to send (`refresh` or `revoke`).
|
|
10
|
+
* @param to - The target {@link Worker} instance.
|
|
11
|
+
* @returns A Promise that resolves with the worker's response payload.
|
|
12
|
+
*/
|
|
13
|
+
export declare const sendMessage: <T = any>(message: WorkerRefreshTokenMessage | WorkerRevokeTokenMessage | WorkerClearMessage, to: Worker) => Promise<T>;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@auth0/auth0-spa-js",
|
|
4
4
|
"description": "Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "2.19.
|
|
6
|
+
"version": "2.19.2",
|
|
7
7
|
"main": "dist/lib/auth0-spa-js.cjs.js",
|
|
8
8
|
"types": "dist/typings/index.d.ts",
|
|
9
9
|
"module": "dist/auth0-spa-js.production.esm.js",
|
package/src/Auth0Client.ts
CHANGED
|
@@ -96,6 +96,7 @@ import {
|
|
|
96
96
|
|
|
97
97
|
// @ts-ignore
|
|
98
98
|
import TokenWorker from './worker/token.worker.ts';
|
|
99
|
+
import { sendMessage } from './worker/worker.utils';
|
|
99
100
|
import { singlePromise, retryPromise } from './promise-utils';
|
|
100
101
|
import { CacheKeyManifest } from './cache/key-manifest';
|
|
101
102
|
import {
|
|
@@ -1247,6 +1248,15 @@ export class Auth0Client {
|
|
|
1247
1248
|
|
|
1248
1249
|
await this.dpop?.clear();
|
|
1249
1250
|
|
|
1251
|
+
if (this.worker) {
|
|
1252
|
+
try {
|
|
1253
|
+
await sendMessage({ type: 'clear' }, this.worker);
|
|
1254
|
+
} catch {
|
|
1255
|
+
// Worker is an internal, best-effort cleanup channel. If the ACK round-trip
|
|
1256
|
+
// fails we still proceed with logout so the user is not left in a half-state.
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1250
1260
|
const url = this._buildLogoutUrl(logoutOptions);
|
|
1251
1261
|
|
|
1252
1262
|
if (openUrl) {
|
package/src/api.ts
CHANGED
|
@@ -130,17 +130,21 @@ export async function revokeToken(
|
|
|
130
130
|
? createQueryParams(baseParams)
|
|
131
131
|
: JSON.stringify(baseParams);
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
133
|
+
try {
|
|
134
|
+
return await sendMessage(
|
|
135
|
+
{
|
|
136
|
+
type: 'revoke',
|
|
137
|
+
timeout: resolvedTimeout,
|
|
138
|
+
fetchUrl,
|
|
139
|
+
fetchOptions: { method: 'POST', body, headers },
|
|
140
|
+
useFormData,
|
|
141
|
+
auth: { audience: audience ?? DEFAULT_AUDIENCE }
|
|
142
|
+
},
|
|
143
|
+
worker
|
|
144
|
+
);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
throw new GenericError('revoke_error', (e as Error).message);
|
|
147
|
+
}
|
|
144
148
|
}
|
|
145
149
|
|
|
146
150
|
for (const refreshToken of refreshTokens) {
|
|
@@ -77,6 +77,11 @@ export class CacheManager {
|
|
|
77
77
|
cacheKey.toKey()
|
|
78
78
|
);
|
|
79
79
|
|
|
80
|
+
// Track the key where the entry was actually found, so that
|
|
81
|
+
// expiry-related writes (strip / remove) target the correct entry
|
|
82
|
+
// instead of creating a ghost entry under the lookup key.
|
|
83
|
+
let resolvedCacheKey = cacheKey;
|
|
84
|
+
|
|
80
85
|
if (!wrappedEntry) {
|
|
81
86
|
const keys = await this.getCacheKeys();
|
|
82
87
|
|
|
@@ -86,6 +91,7 @@ export class CacheManager {
|
|
|
86
91
|
|
|
87
92
|
if (matchedKey) {
|
|
88
93
|
wrappedEntry = await this.cache.get<WrappedCacheEntry>(matchedKey);
|
|
94
|
+
resolvedCacheKey = CacheKey.fromKey(matchedKey);
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
// To refresh using MRRT we need to send a request to the server
|
|
@@ -106,11 +112,11 @@ export class CacheManager {
|
|
|
106
112
|
|
|
107
113
|
if (wrappedEntry.expiresAt - expiryAdjustmentSeconds < nowSeconds) {
|
|
108
114
|
if (wrappedEntry.body.refresh_token) {
|
|
109
|
-
return this.modifiedCachedEntry(wrappedEntry,
|
|
115
|
+
return this.modifiedCachedEntry(wrappedEntry, resolvedCacheKey);
|
|
110
116
|
}
|
|
111
117
|
|
|
112
|
-
await this.cache.remove(
|
|
113
|
-
await this.keyManifest?.remove(
|
|
118
|
+
await this.cache.remove(resolvedCacheKey.toKey());
|
|
119
|
+
await this.keyManifest?.remove(resolvedCacheKey.toKey());
|
|
114
120
|
|
|
115
121
|
return;
|
|
116
122
|
}
|
|
@@ -121,18 +127,27 @@ export class CacheManager {
|
|
|
121
127
|
private async modifiedCachedEntry(wrappedEntry: WrappedCacheEntry, cacheKey: CacheKey): Promise<Partial<CacheEntry>> {
|
|
122
128
|
// We need to keep audience and scope in order to check them later when doing refresh
|
|
123
129
|
// using MRRT. See getScopeToRequest method.
|
|
124
|
-
|
|
130
|
+
//
|
|
131
|
+
// Build a new object instead of mutating wrappedEntry.body in-place,
|
|
132
|
+
// because InMemoryCache returns direct references — mutating would
|
|
133
|
+
// corrupt the original entry stored under a different (superset) key.
|
|
134
|
+
const strippedBody: Partial<CacheEntry> = {
|
|
125
135
|
refresh_token: wrappedEntry.body.refresh_token,
|
|
126
136
|
audience: wrappedEntry.body.audience,
|
|
127
137
|
scope: wrappedEntry.body.scope,
|
|
128
138
|
};
|
|
129
139
|
|
|
130
|
-
|
|
140
|
+
const strippedEntry: WrappedCacheEntry = {
|
|
141
|
+
body: strippedBody,
|
|
142
|
+
expiresAt: wrappedEntry.expiresAt,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
await this.cache.set(cacheKey.toKey(), strippedEntry);
|
|
131
146
|
|
|
132
147
|
return {
|
|
133
|
-
refresh_token:
|
|
134
|
-
audience:
|
|
135
|
-
scope:
|
|
148
|
+
refresh_token: strippedBody.refresh_token,
|
|
149
|
+
audience: strippedBody.audience,
|
|
150
|
+
scope: strippedBody.scope,
|
|
136
151
|
};
|
|
137
152
|
}
|
|
138
153
|
|
|
@@ -278,7 +293,11 @@ export class CacheManager {
|
|
|
278
293
|
const cachedEntry = await this.cache.get<WrappedCacheEntry>(key);
|
|
279
294
|
|
|
280
295
|
if (cachedEntry?.body?.refresh_token) {
|
|
281
|
-
return
|
|
296
|
+
return {
|
|
297
|
+
refresh_token: cachedEntry.body.refresh_token,
|
|
298
|
+
audience: cachedEntry.body.audience,
|
|
299
|
+
scope: cachedEntry.body.scope,
|
|
300
|
+
};
|
|
282
301
|
}
|
|
283
302
|
}
|
|
284
303
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '2.19.
|
|
1
|
+
export default '2.19.2';
|
|
@@ -316,6 +316,12 @@ const messageRouter = (event: MessageEvent<WorkerMessage>) => {
|
|
|
316
316
|
return;
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
+
if ('type' in data && data.type === 'clear') {
|
|
320
|
+
refreshTokens = {};
|
|
321
|
+
port?.postMessage({ ok: true });
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
319
325
|
if ('type' in data && data.type === 'revoke') {
|
|
320
326
|
if (!isAuthorizedWorkerRequest(data as WorkerRevokeTokenMessage, '/oauth/revoke')) {
|
|
321
327
|
port?.postMessage({
|
|
@@ -28,7 +28,12 @@ export type WorkerRevokeTokenMessage = Omit<WorkerTokenMessage, 'auth'> & {
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
export type WorkerClearMessage = {
|
|
32
|
+
type: 'clear';
|
|
33
|
+
};
|
|
34
|
+
|
|
31
35
|
export type WorkerMessage =
|
|
32
36
|
| WorkerInitMessage
|
|
33
37
|
| WorkerRefreshTokenMessage
|
|
34
|
-
| WorkerRevokeTokenMessage
|
|
38
|
+
| WorkerRevokeTokenMessage
|
|
39
|
+
| WorkerClearMessage;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
WorkerClearMessage,
|
|
2
3
|
WorkerRefreshTokenMessage,
|
|
3
4
|
WorkerRevokeTokenMessage
|
|
4
5
|
} from './worker.types';
|
|
@@ -15,7 +16,10 @@ import {
|
|
|
15
16
|
* @returns A Promise that resolves with the worker's response payload.
|
|
16
17
|
*/
|
|
17
18
|
export const sendMessage = <T = any>(
|
|
18
|
-
message:
|
|
19
|
+
message:
|
|
20
|
+
| WorkerRefreshTokenMessage
|
|
21
|
+
| WorkerRevokeTokenMessage
|
|
22
|
+
| WorkerClearMessage,
|
|
19
23
|
to: Worker
|
|
20
24
|
): Promise<T> =>
|
|
21
25
|
new Promise<T>(function (resolve, reject) {
|