@auth0/auth0-spa-js 1.19.3 → 1.20.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/README.md +2 -2
- package/dist/auth0-spa-js.development.js +201 -105
- 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/lib/auth0-spa-js.cjs.js +201 -105
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/dist/typings/Auth0Client.d.ts +13 -12
- package/dist/typings/global.d.ts +4 -0
- package/dist/typings/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/Auth0Client.ts +46 -27
- package/src/cache/cache-manager.ts +4 -1
- package/src/global.ts +5 -0
- package/src/http.ts +2 -0
- package/src/version.ts +1 -1
|
@@ -4,18 +4,19 @@ import { Auth0ClientOptions, RedirectLoginOptions, PopupLoginOptions, PopupConfi
|
|
|
4
4
|
*/
|
|
5
5
|
export default class Auth0Client {
|
|
6
6
|
private options;
|
|
7
|
-
private transactionManager;
|
|
8
|
-
private cacheManager;
|
|
9
|
-
private customOptions;
|
|
10
|
-
private domainUrl;
|
|
11
|
-
private tokenIssuer;
|
|
12
|
-
private defaultScope;
|
|
13
|
-
private scope;
|
|
14
|
-
private cookieStorage;
|
|
15
|
-
private sessionCheckExpiryDays;
|
|
16
|
-
private orgHintCookieName;
|
|
17
|
-
private isAuthenticatedCookieName;
|
|
18
|
-
private nowProvider;
|
|
7
|
+
private readonly transactionManager;
|
|
8
|
+
private readonly cacheManager;
|
|
9
|
+
private readonly customOptions;
|
|
10
|
+
private readonly domainUrl;
|
|
11
|
+
private readonly tokenIssuer;
|
|
12
|
+
private readonly defaultScope;
|
|
13
|
+
private readonly scope;
|
|
14
|
+
private readonly cookieStorage;
|
|
15
|
+
private readonly sessionCheckExpiryDays;
|
|
16
|
+
private readonly orgHintCookieName;
|
|
17
|
+
private readonly isAuthenticatedCookieName;
|
|
18
|
+
private readonly nowProvider;
|
|
19
|
+
private readonly httpTimeoutMs;
|
|
19
20
|
cacheLocation: CacheLocation;
|
|
20
21
|
private worker;
|
|
21
22
|
constructor(options: Auth0ClientOptions);
|
package/dist/typings/global.d.ts
CHANGED
|
@@ -143,6 +143,10 @@ export interface Auth0ClientOptions extends BaseLoginOptions {
|
|
|
143
143
|
* Defaults to 60s.
|
|
144
144
|
*/
|
|
145
145
|
authorizeTimeoutInSeconds?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Specify the timeout for HTTP calls using `fetch`. The default is 10 seconds.
|
|
148
|
+
*/
|
|
149
|
+
httpTimeoutInSeconds?: number;
|
|
146
150
|
/**
|
|
147
151
|
* Internal property to send information about the client to the authorization server.
|
|
148
152
|
* @internal
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.20.1";
|
|
2
2
|
export default _default;
|
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": "1.
|
|
6
|
+
"version": "1.20.1",
|
|
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",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"abortcontroller-polyfill": "^1.7.3",
|
|
83
83
|
"browser-tabs-lock": "^1.2.15",
|
|
84
|
-
"core-js": "^3.
|
|
84
|
+
"core-js": "^3.20.3",
|
|
85
85
|
"es-cookie": "^1.3.2",
|
|
86
86
|
"fast-text-encoding": "^1.0.3",
|
|
87
87
|
"promise-polyfill": "^8.2.1",
|
package/src/Auth0Client.ts
CHANGED
|
@@ -46,7 +46,8 @@ import {
|
|
|
46
46
|
DEFAULT_SESSION_CHECK_EXPIRY_DAYS,
|
|
47
47
|
DEFAULT_AUTH0_CLIENT,
|
|
48
48
|
INVALID_REFRESH_TOKEN_ERROR_MESSAGE,
|
|
49
|
-
DEFAULT_NOW_PROVIDER
|
|
49
|
+
DEFAULT_NOW_PROVIDER,
|
|
50
|
+
DEFAULT_FETCH_TIMEOUT_MS
|
|
50
51
|
} from './constants';
|
|
51
52
|
|
|
52
53
|
import {
|
|
@@ -188,18 +189,19 @@ const getCustomInitialOptions = (
|
|
|
188
189
|
* Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce).
|
|
189
190
|
*/
|
|
190
191
|
export default class Auth0Client {
|
|
191
|
-
private transactionManager: TransactionManager;
|
|
192
|
-
private cacheManager: CacheManager;
|
|
193
|
-
private customOptions: BaseLoginOptions;
|
|
194
|
-
private domainUrl: string;
|
|
195
|
-
private tokenIssuer: string;
|
|
196
|
-
private defaultScope: string;
|
|
197
|
-
private scope: string;
|
|
198
|
-
private cookieStorage: ClientStorage;
|
|
199
|
-
private sessionCheckExpiryDays: number;
|
|
200
|
-
private orgHintCookieName: string;
|
|
201
|
-
private isAuthenticatedCookieName: string;
|
|
202
|
-
private nowProvider: () => number | Promise<number>;
|
|
192
|
+
private readonly transactionManager: TransactionManager;
|
|
193
|
+
private readonly cacheManager: CacheManager;
|
|
194
|
+
private readonly customOptions: BaseLoginOptions;
|
|
195
|
+
private readonly domainUrl: string;
|
|
196
|
+
private readonly tokenIssuer: string;
|
|
197
|
+
private readonly defaultScope: string;
|
|
198
|
+
private readonly scope: string;
|
|
199
|
+
private readonly cookieStorage: ClientStorage;
|
|
200
|
+
private readonly sessionCheckExpiryDays: number;
|
|
201
|
+
private readonly orgHintCookieName: string;
|
|
202
|
+
private readonly isAuthenticatedCookieName: string;
|
|
203
|
+
private readonly nowProvider: () => number | Promise<number>;
|
|
204
|
+
private readonly httpTimeoutMs: number;
|
|
203
205
|
|
|
204
206
|
cacheLocation: CacheLocation;
|
|
205
207
|
private worker: Worker;
|
|
@@ -227,6 +229,10 @@ export default class Auth0Client {
|
|
|
227
229
|
cache = cacheFactory(this.cacheLocation)();
|
|
228
230
|
}
|
|
229
231
|
|
|
232
|
+
this.httpTimeoutMs = options.httpTimeoutInSeconds
|
|
233
|
+
? options.httpTimeoutInSeconds * 1000
|
|
234
|
+
: DEFAULT_FETCH_TIMEOUT_MS;
|
|
235
|
+
|
|
230
236
|
this.cookieStorage =
|
|
231
237
|
options.legacySameSiteCookie === false
|
|
232
238
|
? CookieStorage
|
|
@@ -326,6 +332,7 @@ export default class Auth0Client {
|
|
|
326
332
|
sessionCheckExpiryDays,
|
|
327
333
|
domain,
|
|
328
334
|
leeway,
|
|
335
|
+
httpTimeoutInSeconds,
|
|
329
336
|
...loginOptions
|
|
330
337
|
} = this.options;
|
|
331
338
|
|
|
@@ -379,7 +386,9 @@ export default class Auth0Client {
|
|
|
379
386
|
|
|
380
387
|
private _processOrgIdHint(organizationId?: string) {
|
|
381
388
|
if (organizationId) {
|
|
382
|
-
this.cookieStorage.save(this.orgHintCookieName, organizationId
|
|
389
|
+
this.cookieStorage.save(this.orgHintCookieName, organizationId, {
|
|
390
|
+
daysUntilExpire: this.sessionCheckExpiryDays
|
|
391
|
+
});
|
|
383
392
|
} else {
|
|
384
393
|
this.cookieStorage.remove(this.orgHintCookieName);
|
|
385
394
|
}
|
|
@@ -512,7 +521,8 @@ export default class Auth0Client {
|
|
|
512
521
|
grant_type: 'authorization_code',
|
|
513
522
|
redirect_uri: params.redirect_uri,
|
|
514
523
|
auth0Client: this.options.auth0Client,
|
|
515
|
-
useFormData: this.options.useFormData
|
|
524
|
+
useFormData: this.options.useFormData,
|
|
525
|
+
timeout: this.httpTimeoutMs
|
|
516
526
|
} as OAuthTokenOptions,
|
|
517
527
|
this.worker
|
|
518
528
|
);
|
|
@@ -676,7 +686,8 @@ export default class Auth0Client {
|
|
|
676
686
|
grant_type: 'authorization_code',
|
|
677
687
|
code,
|
|
678
688
|
auth0Client: this.options.auth0Client,
|
|
679
|
-
useFormData: this.options.useFormData
|
|
689
|
+
useFormData: this.options.useFormData,
|
|
690
|
+
timeout: this.httpTimeoutMs
|
|
680
691
|
} as OAuthTokenOptions;
|
|
681
692
|
// some old versions of the SDK might not have added redirect_uri to the
|
|
682
693
|
// transaction, we dont want the key to be set to undefined.
|
|
@@ -785,11 +796,17 @@ export default class Auth0Client {
|
|
|
785
796
|
* const token = await auth0.getTokenSilently(options);
|
|
786
797
|
* ```
|
|
787
798
|
*
|
|
788
|
-
* If there's a valid token stored
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
* will be
|
|
799
|
+
* If there's a valid token stored and it has more than 60 seconds
|
|
800
|
+
* remaining before expiration, return the token. Otherwise, attempt
|
|
801
|
+
* to obtain a new token.
|
|
802
|
+
*
|
|
803
|
+
* A new token will be obtained either by opening an iframe or a
|
|
804
|
+
* refresh token (if `useRefreshTokens` is `true`)
|
|
805
|
+
|
|
806
|
+
* If iframes are used, opens an iframe with the `/authorize` URL
|
|
807
|
+
* using the parameters provided as arguments. Random and secure `state`
|
|
808
|
+
* and `nonce` parameters will be auto-generated. If the response is successful,
|
|
809
|
+
* results will be validated according to their expiration times.
|
|
793
810
|
*
|
|
794
811
|
* If refresh tokens are used, the token endpoint is called directly with the
|
|
795
812
|
* 'refresh_token' grant. If no refresh token is available to make this call,
|
|
@@ -1061,9 +1078,6 @@ export default class Auth0Client {
|
|
|
1061
1078
|
response_mode: 'web_message'
|
|
1062
1079
|
});
|
|
1063
1080
|
|
|
1064
|
-
const timeout =
|
|
1065
|
-
options.timeoutInSeconds || this.options.authorizeTimeoutInSeconds;
|
|
1066
|
-
|
|
1067
1081
|
try {
|
|
1068
1082
|
// When a browser is running in a Cross-Origin Isolated context, using iframes is not possible.
|
|
1069
1083
|
// It doesn't throw an error but times out instead, so we should exit early and inform the user about the reason.
|
|
@@ -1075,7 +1089,10 @@ export default class Auth0Client {
|
|
|
1075
1089
|
);
|
|
1076
1090
|
}
|
|
1077
1091
|
|
|
1078
|
-
const
|
|
1092
|
+
const authorizeTimeout =
|
|
1093
|
+
options.timeoutInSeconds || this.options.authorizeTimeoutInSeconds;
|
|
1094
|
+
|
|
1095
|
+
const codeResult = await runIframe(url, this.domainUrl, authorizeTimeout);
|
|
1079
1096
|
|
|
1080
1097
|
if (stateIn !== codeResult.state) {
|
|
1081
1098
|
throw new Error('Invalid state');
|
|
@@ -1104,7 +1121,8 @@ export default class Auth0Client {
|
|
|
1104
1121
|
grant_type: 'authorization_code',
|
|
1105
1122
|
redirect_uri: params.redirect_uri,
|
|
1106
1123
|
auth0Client: this.options.auth0Client,
|
|
1107
|
-
useFormData: this.options.useFormData
|
|
1124
|
+
useFormData: this.options.useFormData,
|
|
1125
|
+
timeout: customOptions.timeout || this.httpTimeoutMs
|
|
1108
1126
|
} as OAuthTokenOptions,
|
|
1109
1127
|
this.worker
|
|
1110
1128
|
);
|
|
@@ -1192,7 +1210,8 @@ export default class Auth0Client {
|
|
|
1192
1210
|
redirect_uri,
|
|
1193
1211
|
...(timeout && { timeout }),
|
|
1194
1212
|
auth0Client: this.options.auth0Client,
|
|
1195
|
-
useFormData: this.options.useFormData
|
|
1213
|
+
useFormData: this.options.useFormData,
|
|
1214
|
+
timeout: this.httpTimeoutMs
|
|
1196
1215
|
} as RefreshTokenOptions,
|
|
1197
1216
|
this.worker
|
|
1198
1217
|
);
|
|
@@ -34,7 +34,10 @@ export class CacheManager {
|
|
|
34
34
|
if (!keys) return;
|
|
35
35
|
|
|
36
36
|
const matchedKey = this.matchExistingCacheKey(cacheKey, keys);
|
|
37
|
-
|
|
37
|
+
|
|
38
|
+
if (matchedKey) {
|
|
39
|
+
wrappedEntry = await this.cache.get<WrappedCacheEntry>(matchedKey);
|
|
40
|
+
}
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
// If we still don't have an entry, exit.
|
package/src/global.ts
CHANGED
|
@@ -164,6 +164,11 @@ export interface Auth0ClientOptions extends BaseLoginOptions {
|
|
|
164
164
|
*/
|
|
165
165
|
authorizeTimeoutInSeconds?: number;
|
|
166
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Specify the timeout for HTTP calls using `fetch`. The default is 10 seconds.
|
|
169
|
+
*/
|
|
170
|
+
httpTimeoutInSeconds?: number;
|
|
171
|
+
|
|
167
172
|
/**
|
|
168
173
|
* Internal property to send information about the client to the authorization server.
|
|
169
174
|
* @internal
|
package/src/http.ts
CHANGED
|
@@ -13,6 +13,7 @@ export const createAbortController = () => new AbortController();
|
|
|
13
13
|
|
|
14
14
|
const dofetch = async (fetchUrl: string, fetchOptions: FetchOptions) => {
|
|
15
15
|
const response = await fetch(fetchUrl, fetchOptions);
|
|
16
|
+
|
|
16
17
|
return {
|
|
17
18
|
ok: response.ok,
|
|
18
19
|
json: await response.json()
|
|
@@ -32,6 +33,7 @@ const fetchWithoutWorker = async (
|
|
|
32
33
|
// The promise will resolve with one of these two promises (the fetch or the timeout), whichever completes first.
|
|
33
34
|
return Promise.race([
|
|
34
35
|
dofetch(fetchUrl, fetchOptions),
|
|
36
|
+
|
|
35
37
|
new Promise((_, reject) => {
|
|
36
38
|
timeoutId = setTimeout(() => {
|
|
37
39
|
controller.abort();
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.
|
|
1
|
+
export default '1.20.1';
|