@auth0/auth0-spa-js 2.15.0 → 2.16.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.
@@ -18,7 +18,7 @@ typeof SuppressedError === "function" ? SuppressedError : function(error, suppre
18
18
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
19
19
  };
20
20
 
21
- var version = "2.15.0";
21
+ var version = "2.16.0";
22
22
 
23
23
  const DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
24
24
 
@@ -8293,29 +8293,57 @@ class Auth0Client {
8293
8293
  return;
8294
8294
  }
8295
8295
  const lockKey = buildGetTokenSilentlyLockKey(this.options.clientId, getTokenOptions.authorizationParams.audience || "default");
8296
- return await this.lockManager.runWithLock(lockKey, 5e3, (async () => {
8297
- if (cacheMode !== "off") {
8298
- const entry = await this._getEntryFromCache({
8299
- scope: getTokenOptions.authorizationParams.scope,
8300
- audience: getTokenOptions.authorizationParams.audience || DEFAULT_AUDIENCE,
8301
- clientId: this.options.clientId
8302
- });
8303
- if (entry) {
8304
- return entry;
8296
+ try {
8297
+ return await this.lockManager.runWithLock(lockKey, 5e3, (async () => {
8298
+ if (cacheMode !== "off") {
8299
+ const entry = await this._getEntryFromCache({
8300
+ scope: getTokenOptions.authorizationParams.scope,
8301
+ audience: getTokenOptions.authorizationParams.audience || DEFAULT_AUDIENCE,
8302
+ clientId: this.options.clientId
8303
+ });
8304
+ if (entry) {
8305
+ return entry;
8306
+ }
8305
8307
  }
8308
+ const authResult = this.options.useRefreshTokens ? await this._getTokenUsingRefreshToken(getTokenOptions) : await this._getTokenFromIFrame(getTokenOptions);
8309
+ const {id_token: id_token, token_type: token_type, access_token: access_token, oauthTokenScope: oauthTokenScope, expires_in: expires_in} = authResult;
8310
+ return Object.assign(Object.assign({
8311
+ id_token: id_token,
8312
+ token_type: token_type,
8313
+ access_token: access_token
8314
+ }, oauthTokenScope ? {
8315
+ scope: oauthTokenScope
8316
+ } : null), {
8317
+ expires_in: expires_in
8318
+ });
8319
+ }));
8320
+ } catch (error) {
8321
+ if (this._isInteractiveError(error) && this.options.interactiveErrorHandler === "popup") {
8322
+ return await this._handleInteractiveErrorWithPopup(getTokenOptions);
8306
8323
  }
8307
- const authResult = this.options.useRefreshTokens ? await this._getTokenUsingRefreshToken(getTokenOptions) : await this._getTokenFromIFrame(getTokenOptions);
8308
- const {id_token: id_token, token_type: token_type, access_token: access_token, oauthTokenScope: oauthTokenScope, expires_in: expires_in} = authResult;
8309
- return Object.assign(Object.assign({
8310
- id_token: id_token,
8311
- token_type: token_type,
8312
- access_token: access_token
8313
- }, oauthTokenScope ? {
8314
- scope: oauthTokenScope
8315
- } : null), {
8316
- expires_in: expires_in
8324
+ throw error;
8325
+ }
8326
+ }
8327
+ _isInteractiveError(error) {
8328
+ return error instanceof MfaRequiredError;
8329
+ }
8330
+ async _handleInteractiveErrorWithPopup(options) {
8331
+ try {
8332
+ await this.loginWithPopup({
8333
+ authorizationParams: options.authorizationParams
8317
8334
  });
8318
- }));
8335
+ const entry = await this._getEntryFromCache({
8336
+ scope: options.authorizationParams.scope,
8337
+ audience: options.authorizationParams.audience || DEFAULT_AUDIENCE,
8338
+ clientId: this.options.clientId
8339
+ });
8340
+ if (!entry) {
8341
+ throw new GenericError("interactive_handler_cache_miss", "Token not found in cache after interactive authentication");
8342
+ }
8343
+ return entry;
8344
+ } catch (error) {
8345
+ throw error;
8346
+ }
8319
8347
  }
8320
8348
  async getTokenWithPopup() {
8321
8349
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};