@auth0/auth0-spa-js 1.18.0 → 1.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { Auth0ClientOptions, RedirectLoginOptions, PopupLoginOptions, PopupConfigOptions, GetUserOptions, GetIdTokenClaimsOptions, RedirectLoginResult, GetTokenSilentlyOptions, GetTokenWithPopupOptions, LogoutOptions, CacheLocation, LogoutUrlOptions, User, IdToken } from './global';
1
+ import { Auth0ClientOptions, RedirectLoginOptions, PopupLoginOptions, PopupConfigOptions, GetUserOptions, GetIdTokenClaimsOptions, RedirectLoginResult, GetTokenSilentlyOptions, GetTokenWithPopupOptions, LogoutOptions, CacheLocation, LogoutUrlOptions, User, IdToken, GetTokenSilentlyVerboseResponse } from './global';
2
2
  /**
3
3
  * Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce).
4
4
  */
@@ -15,6 +15,7 @@ export default class Auth0Client {
15
15
  private sessionCheckExpiryDays;
16
16
  private orgHintCookieName;
17
17
  private isAuthenticatedCookieName;
18
+ private nowProvider;
18
19
  cacheLocation: CacheLocation;
19
20
  private worker;
20
21
  constructor(options: Auth0ClientOptions);
@@ -89,7 +90,7 @@ export default class Auth0Client {
89
90
  *
90
91
  * @param options
91
92
  */
92
- getIdTokenClaims(options?: GetIdTokenClaimsOptions): Promise<IdToken>;
93
+ getIdTokenClaims(options?: GetIdTokenClaimsOptions): Promise<IdToken | undefined>;
93
94
  /**
94
95
  * ```js
95
96
  * await auth0.loginWithRedirect(options);
@@ -101,14 +102,14 @@ export default class Auth0Client {
101
102
  *
102
103
  * @param options
103
104
  */
104
- loginWithRedirect(options?: RedirectLoginOptions): Promise<void>;
105
+ loginWithRedirect<TAppState = any>(options?: RedirectLoginOptions<TAppState>): Promise<void>;
105
106
  /**
106
107
  * After the browser redirects back to the callback page,
107
108
  * call `handleRedirectCallback` to handle success and error
108
109
  * responses from Auth0. If the response is successful, results
109
110
  * will be valid according to their expiration times.
110
111
  */
111
- handleRedirectCallback(url?: string): Promise<RedirectLoginResult>;
112
+ handleRedirectCallback<TAppState = any>(url?: string): Promise<RedirectLoginResult<TAppState>>;
112
113
  /**
113
114
  * ```js
114
115
  * await auth0.checkSession();
@@ -126,36 +127,29 @@ export default class Auth0Client {
126
127
  * `Auth0Client` constructor. You should not need this if you are using the
127
128
  * `createAuth0Client` factory.
128
129
  *
130
+ * **Note:** the cookie **may not** be present if running an app using a private tab, as some
131
+ * browsers clear JS cookie data and local storage when the tab or page is closed, or on page reload. This effectively
132
+ * means that `checkSession` could silently return without authenticating the user on page refresh when
133
+ * using a private tab, despite having previously logged in. As a workaround, use `getTokenSilently` instead
134
+ * and handle the possible `login_required` error [as shown in the readme](https://github.com/auth0/auth0-spa-js#creating-the-client).
135
+ *
129
136
  * @param options
130
137
  */
131
138
  checkSession(options?: GetTokenSilentlyOptions): Promise<void>;
132
139
  /**
133
- * ```js
134
- * const token = await auth0.getTokenSilently(options);
135
- * ```
136
- *
137
- * If there's a valid token stored, return it. Otherwise, opens an
138
- * iframe with the `/authorize` URL using the parameters provided
139
- * as arguments. Random and secure `state` and `nonce` parameters
140
- * will be auto-generated. If the response is successful, results
141
- * will be valid according to their expiration times.
142
- *
143
- * If refresh tokens are used, the token endpoint is called directly with the
144
- * 'refresh_token' grant. If no refresh token is available to make this call,
145
- * the SDK falls back to using an iframe to the '/authorize' URL.
140
+ * Fetches a new access token and returns the response from the /oauth/token endpoint, omitting the refresh token.
146
141
  *
147
- * This method may use a web worker to perform the token call if the in-memory
148
- * cache is used.
149
- *
150
- * If an `audience` value is given to this function, the SDK always falls
151
- * back to using an iframe to make the token exchange.
152
- *
153
- * Note that in all cases, falling back to an iframe requires access to
154
- * the `auth0` cookie.
142
+ * @param options
143
+ */
144
+ getTokenSilently(options: GetTokenSilentlyOptions & {
145
+ detailedResponse: true;
146
+ }): Promise<GetTokenSilentlyVerboseResponse>;
147
+ /**
148
+ * Fetches a new access token and returns it.
155
149
  *
156
150
  * @param options
157
151
  */
158
- getTokenSilently(options?: GetTokenSilentlyOptions): Promise<any>;
152
+ getTokenSilently(options?: GetTokenSilentlyOptions): Promise<string>;
159
153
  private _getTokenSilently;
160
154
  /**
161
155
  * ```js
@@ -210,4 +204,5 @@ export default class Auth0Client {
210
204
  logout(options?: LogoutOptions): Promise<void> | void;
211
205
  private _getTokenFromIFrame;
212
206
  private _getTokenUsingRefreshToken;
207
+ private _getEntryFromCache;
213
208
  }
@@ -1,9 +1,2 @@
1
- import { TokenEndpointOptions } from './global';
2
- export declare type TokenEndpointResponse = {
3
- id_token: string;
4
- access_token: string;
5
- refresh_token?: string;
6
- expires_in: number;
7
- scope?: string;
8
- };
1
+ import { TokenEndpointOptions, TokenEndpointResponse } from './global';
9
2
  export declare function oauthToken({ baseUrl, timeout, audience, scope, auth0Client, useFormData, ...options }: TokenEndpointOptions, worker?: Worker): Promise<TokenEndpointResponse>;
@@ -3,7 +3,8 @@ import { CacheEntry, ICache, CacheKey } from './shared';
3
3
  export declare class CacheManager {
4
4
  private cache;
5
5
  private keyManifest?;
6
- constructor(cache: ICache, keyManifest?: CacheKeyManifest);
6
+ private nowProvider?;
7
+ constructor(cache: ICache, keyManifest?: CacheKeyManifest, nowProvider?: () => number | Promise<number>);
7
8
  get(cacheKey: CacheKey, expiryAdjustmentSeconds?: number): Promise<Partial<CacheEntry> | undefined>;
8
9
  set(entry: CacheEntry): Promise<void>;
9
10
  clear(clientId?: string): Promise<void>;
@@ -42,6 +42,7 @@ export declare type CacheEntry = {
42
42
  scope: string;
43
43
  client_id: string;
44
44
  refresh_token?: string;
45
+ oauthTokenScope?: string;
45
46
  };
46
47
  export declare type WrappedCacheEntry = {
47
48
  body: Partial<CacheEntry>;
@@ -51,3 +51,4 @@ export declare const DEFAULT_AUTH0_CLIENT: {
51
51
  name: string;
52
52
  version: string;
53
53
  };
54
+ export declare const DEFAULT_NOW_PROVIDER: () => number;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * For context on the istanbul ignore statements below, see:
3
+ * https://github.com/gotwarlost/istanbul/issues/690
4
+ */
1
5
  /**
2
6
  * Thrown when network requests to the Auth server fail.
3
7
  */
@@ -189,6 +189,12 @@ export interface Auth0ClientOptions extends BaseLoginOptions {
189
189
  * continue to work as intended.
190
190
  */
191
191
  useFormData?: boolean;
192
+ /**
193
+ * Modify the value used as the current time during the token validation.
194
+ *
195
+ * **Note**: Using this improperly can potentially compromise the token validation.
196
+ */
197
+ nowProvider?: () => Promise<number> | number;
192
198
  }
193
199
  /**
194
200
  * The possible locations where tokens can be stored
@@ -207,7 +213,7 @@ export interface AuthorizeOptions extends BaseLoginOptions {
207
213
  code_challenge: string;
208
214
  code_challenge_method: string;
209
215
  }
210
- export interface RedirectLoginOptions extends BaseLoginOptions {
216
+ export interface RedirectLoginOptions<TAppState = any> extends BaseLoginOptions {
211
217
  /**
212
218
  * The URL where Auth0 will redirect your browser to with
213
219
  * the authentication result. It must be whitelisted in
@@ -218,7 +224,7 @@ export interface RedirectLoginOptions extends BaseLoginOptions {
218
224
  /**
219
225
  * Used to store state before doing the redirect
220
226
  */
221
- appState?: any;
227
+ appState?: TAppState;
222
228
  /**
223
229
  * Used to add to the URL fragment before redirecting
224
230
  */
@@ -228,11 +234,11 @@ export interface RedirectLoginOptions extends BaseLoginOptions {
228
234
  */
229
235
  redirectMethod?: 'replace' | 'assign';
230
236
  }
231
- export interface RedirectLoginResult {
237
+ export interface RedirectLoginResult<TAppState = any> {
232
238
  /**
233
239
  * State stored when the redirect request was made
234
240
  */
235
- appState?: any;
241
+ appState?: TAppState;
236
242
  }
237
243
  export interface PopupLoginOptions extends BaseLoginOptions {
238
244
  }
@@ -297,6 +303,13 @@ export interface GetTokenSilentlyOptions {
297
303
  * Defaults to 60s.
298
304
  */
299
305
  timeoutInSeconds?: number;
306
+ /**
307
+ * If true, the full response from the /oauth/token endpoint (or the cache, if the cache was used) is returned
308
+ * (minus `refresh_token` if one was issued). Otherwise, just the access token is returned.
309
+ *
310
+ * The default is `false`.
311
+ */
312
+ detailedResponse?: boolean;
300
313
  /**
301
314
  * If you need to send custom parameters to the Authorization Server,
302
315
  * make sure to use the original parameter name.
@@ -304,6 +317,11 @@ export interface GetTokenSilentlyOptions {
304
317
  [key: string]: any;
305
318
  }
306
319
  export interface GetTokenWithPopupOptions extends PopupLoginOptions {
320
+ /**
321
+ * When `true`, ignores the cache and always sends a
322
+ * request to Auth0.
323
+ */
324
+ ignoreCache?: boolean;
307
325
  }
308
326
  export interface LogoutUrlOptions {
309
327
  /**
@@ -398,6 +416,16 @@ export interface TokenEndpointOptions {
398
416
  useFormData?: boolean;
399
417
  [key: string]: any;
400
418
  }
419
+ /**
420
+ * @ignore
421
+ */
422
+ export declare type TokenEndpointResponse = {
423
+ id_token: string;
424
+ access_token: string;
425
+ refresh_token?: string;
426
+ expires_in: number;
427
+ scope?: string;
428
+ };
401
429
  /**
402
430
  * @ignore
403
431
  */
@@ -425,6 +453,7 @@ export interface JWTVerifyOptions {
425
453
  leeway?: number;
426
454
  max_age?: number;
427
455
  organizationId?: string;
456
+ now?: number;
428
457
  }
429
458
  /**
430
459
  * @ignore
@@ -502,4 +531,5 @@ export declare type FetchOptions = {
502
531
  body?: string;
503
532
  signal?: AbortSignal;
504
533
  };
534
+ export declare type GetTokenSilentlyVerboseResponse = Omit<TokenEndpointResponse, 'refresh_token'>;
505
535
  export {};
@@ -12,6 +12,15 @@ import Auth0Client from './Auth0Client';
12
12
  import { Auth0ClientOptions } from './global';
13
13
  import './global';
14
14
  export * from './global';
15
+ /**
16
+ * Asynchronously creates the Auth0Client instance and calls `checkSession`.
17
+ *
18
+ * **Note:** There are caveats to using this in a private browser tab, which may not silently authenticae
19
+ * a user on page refresh. Please see [the checkSession docs](https://auth0.github.io/auth0-spa-js/classes/auth0client.html#checksession) for more info.
20
+ *
21
+ * @param options The client options
22
+ * @returns An instance of Auth0Client
23
+ */
15
24
  export default function createAuth0Client(options: Auth0ClientOptions): Promise<Auth0Client>;
16
25
  export { Auth0Client };
17
26
  export { GenericError, AuthenticationError, TimeoutError, PopupTimeoutError, PopupCancelledError, MfaRequiredError } from './errors';
@@ -5,7 +5,7 @@ interface ClientStorageOptions {
5
5
  * Defines a type that handles storage to/from a storage location
6
6
  */
7
7
  export declare type ClientStorage = {
8
- get<T extends Object>(key: string): T;
8
+ get<T extends Object>(key: string): T | undefined;
9
9
  save(key: string, value: any, options?: ClientStorageOptions): void;
10
10
  remove(key: string): void;
11
11
  };
@@ -7,6 +7,7 @@ interface Transaction {
7
7
  code_verifier: string;
8
8
  redirect_uri: string;
9
9
  organizationId?: string;
10
+ state?: string;
10
11
  }
11
12
  export default class TransactionManager {
12
13
  private storage;
@@ -15,7 +16,7 @@ export default class TransactionManager {
15
16
  private storageKey;
16
17
  constructor(storage: ClientStorage, clientId: string);
17
18
  create(transaction: Transaction): void;
18
- get(): Transaction;
19
+ get(): Transaction | undefined;
19
20
  remove(): void;
20
21
  }
21
22
  export {};
@@ -1,2 +1,2 @@
1
- declare const _default: "1.18.0";
1
+ declare const _default: "1.19.3";
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.18.0",
6
+ "version": "1.19.3",
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",
@@ -21,7 +21,7 @@
21
21
  "test:watch:integration": "concurrently --raw npm:dev 'npm:test:open:integration'",
22
22
  "test:es-check": "npm run test:es-check:es5 && npm run test:es-check:es2015:module",
23
23
  "test:es-check:es5": "es-check es5 'dist/auth0-spa-js.production.js'",
24
- "test:es-check:es2015:module": "es-check es2015 --module 'dist/auth0-spa-js.production.esm.js'",
24
+ "test:es-check:es2015:module": "es-check es2015 'dist/auth0-spa-js.production.esm.js' --module ",
25
25
  "test:integration:server": "npm run dev",
26
26
  "test:integration:tests": "wait-on http://localhost:3000/ && cypress run",
27
27
  "test:integration": "concurrently --raw --kill-others --success first npm:test:integration:server npm:test:integration:tests",
@@ -35,56 +35,56 @@
35
35
  "@auth0/component-cdn-uploader": "github:auth0/component-cdn-uploader#v2.2.2",
36
36
  "@rollup/plugin-replace": "^2.4.2",
37
37
  "@types/cypress": "^1.1.3",
38
- "@types/jest": "^26.0.24",
39
- "@typescript-eslint/eslint-plugin-tslint": "^4.28.4",
40
- "@typescript-eslint/parser": "^4.28.4",
41
- "browserstack-cypress-cli": "^1.8.1",
38
+ "@types/jest": "^27.0.2",
39
+ "@typescript-eslint/eslint-plugin-tslint": "^4.33.0",
40
+ "@typescript-eslint/parser": "^4.33.0",
41
+ "browserstack-cypress-cli": "1.8.1",
42
42
  "cli-table": "^0.3.6",
43
43
  "codecov": "^3.8.3",
44
- "concurrently": "^5.3.0",
44
+ "concurrently": "^6.4.0",
45
45
  "cypress": "7.2.0",
46
- "es-check": "^5.2.4",
47
- "eslint": "^7.31.0",
48
- "gzip-size": "^5.1.1",
49
- "husky": "^4.3.8",
50
- "idtoken-verifier": "^2.2.0",
51
- "jest": "^26.6.3",
52
- "jest-junit": "^12.2.0",
53
- "jest-localstorage-mock": "^2.4.14",
46
+ "es-check": "^6.1.1",
47
+ "eslint": "^7.32.0",
48
+ "gzip-size": "^6.0.0",
49
+ "husky": "^7.0.4",
50
+ "idtoken-verifier": "^2.2.2",
51
+ "jest": "^27.3.1",
52
+ "jest-junit": "^13.0.0",
53
+ "jest-localstorage-mock": "^2.4.18",
54
54
  "jsonwebtoken": "^8.5.1",
55
- "oidc-provider": "^7.5.4",
55
+ "oidc-provider": "^7.10.1",
56
56
  "pem": "^1.14.4",
57
- "prettier": "^2.3.2",
58
- "pretty-quick": "^3.1.1",
57
+ "prettier": "^2.4.1",
58
+ "pretty-quick": "^3.1.2",
59
59
  "qss": "^2.0.3",
60
60
  "rimraf": "^3.0.2",
61
- "rollup": "^2.53.3",
62
- "rollup-plugin-analyzer": "^3.3.0",
61
+ "rollup": "^2.60.0",
62
+ "rollup-plugin-analyzer": "^4.0.0",
63
63
  "rollup-plugin-commonjs": "^10.1.0",
64
64
  "rollup-plugin-dev": "^1.1.3",
65
65
  "rollup-plugin-livereload": "^2.0.5",
66
66
  "rollup-plugin-node-resolve": "^5.2.0",
67
67
  "rollup-plugin-sourcemaps": "^0.6.3",
68
68
  "rollup-plugin-terser": "^7.0.2",
69
- "rollup-plugin-typescript2": "^0.27.3",
70
- "rollup-plugin-visualizer": "^4.2.2",
69
+ "rollup-plugin-typescript2": "^0.30.0",
70
+ "rollup-plugin-visualizer": "^5.5.2",
71
71
  "rollup-plugin-web-worker-loader": "^1.6.1",
72
- "serve": "^11.3.2",
73
- "ts-jest": "^26.5.6",
74
- "tslib": "^2.3.0",
72
+ "serve": "^12.0.1",
73
+ "ts-jest": "^27.0.7",
74
+ "tslib": "^2.3.1",
75
75
  "tslint": "^6.1.3",
76
76
  "tslint-config-security": "^1.16.0",
77
- "typedoc": "^0.18.0",
78
- "typescript": "^4.3.5",
79
- "wait-on": "^5.3.0"
77
+ "typedoc": "0.18.0",
78
+ "typescript": "^4.4.4",
79
+ "wait-on": "^6.0.0"
80
80
  },
81
81
  "dependencies": {
82
82
  "abortcontroller-polyfill": "^1.7.3",
83
- "browser-tabs-lock": "^1.2.14",
84
- "core-js": "^3.16.3",
83
+ "browser-tabs-lock": "^1.2.15",
84
+ "core-js": "^3.19.0",
85
85
  "es-cookie": "^1.3.2",
86
86
  "fast-text-encoding": "^1.0.3",
87
- "promise-polyfill": "^8.2.0",
87
+ "promise-polyfill": "^8.2.1",
88
88
  "unfetch": "^4.2.0"
89
89
  },
90
90
  "files": [