@auth0/auth0-spa-js 2.15.0 → 2.17.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.
package/README.md CHANGED
@@ -30,7 +30,7 @@ npm install @auth0/auth0-spa-js
30
30
  From the CDN:
31
31
 
32
32
  ```html
33
- <script src="https://cdn.auth0.com/js/auth0-spa-js/2.15/auth0-spa-js.production.js"></script>
33
+ <script src="https://cdn.auth0.com/js/auth0-spa-js/2.17/auth0-spa-js.production.js"></script>
34
34
  ```
35
35
 
36
36
  ### Configure Auth0
@@ -15,7 +15,7 @@
15
15
  var e = new Error(message);
16
16
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
17
17
  };
18
- var version = "2.15.0";
18
+ var version = "2.17.0";
19
19
  const DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
20
20
  const DEFAULT_POPUP_CONFIG_OPTIONS = {
21
21
  timeoutInSeconds: DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS
@@ -27,6 +27,7 @@
27
27
  const MISSING_REFRESH_TOKEN_ERROR_MESSAGE = "Missing Refresh Token";
28
28
  const INVALID_REFRESH_TOKEN_ERROR_MESSAGE = "invalid refresh token";
29
29
  const USER_BLOCKED_ERROR_MESSAGE = "user is blocked";
30
+ const MFA_STEP_UP_ERROR_DESCRIPTION = "Multifactor authentication required";
30
31
  const DEFAULT_SCOPE = "openid profile email";
31
32
  const DEFAULT_SESSION_CHECK_EXPIRY_DAYS = 1;
32
33
  const DEFAULT_AUTH0_CLIENT = {
@@ -7715,29 +7716,60 @@
7715
7716
  return;
7716
7717
  }
7717
7718
  const lockKey = buildGetTokenSilentlyLockKey(this.options.clientId, getTokenOptions.authorizationParams.audience || "default");
7718
- return await this.lockManager.runWithLock(lockKey, 5e3, (async () => {
7719
- if (cacheMode !== "off") {
7720
- const entry = await this._getEntryFromCache({
7721
- scope: getTokenOptions.authorizationParams.scope,
7722
- audience: getTokenOptions.authorizationParams.audience || DEFAULT_AUDIENCE,
7723
- clientId: this.options.clientId
7724
- });
7725
- if (entry) {
7726
- return entry;
7719
+ try {
7720
+ return await this.lockManager.runWithLock(lockKey, 5e3, (async () => {
7721
+ if (cacheMode !== "off") {
7722
+ const entry = await this._getEntryFromCache({
7723
+ scope: getTokenOptions.authorizationParams.scope,
7724
+ audience: getTokenOptions.authorizationParams.audience || DEFAULT_AUDIENCE,
7725
+ clientId: this.options.clientId
7726
+ });
7727
+ if (entry) {
7728
+ return entry;
7729
+ }
7727
7730
  }
7731
+ const authResult = this.options.useRefreshTokens ? await this._getTokenUsingRefreshToken(getTokenOptions) : await this._getTokenFromIFrame(getTokenOptions);
7732
+ const {id_token: id_token, token_type: token_type, access_token: access_token, oauthTokenScope: oauthTokenScope, expires_in: expires_in} = authResult;
7733
+ return Object.assign(Object.assign({
7734
+ id_token: id_token,
7735
+ token_type: token_type,
7736
+ access_token: access_token
7737
+ }, oauthTokenScope ? {
7738
+ scope: oauthTokenScope
7739
+ } : null), {
7740
+ expires_in: expires_in
7741
+ });
7742
+ }));
7743
+ } catch (error) {
7744
+ if (this._isInteractiveError(error) && this.options.interactiveErrorHandler === "popup") {
7745
+ return await this._handleInteractiveErrorWithPopup(getTokenOptions);
7728
7746
  }
7729
- const authResult = this.options.useRefreshTokens ? await this._getTokenUsingRefreshToken(getTokenOptions) : await this._getTokenFromIFrame(getTokenOptions);
7730
- const {id_token: id_token, token_type: token_type, access_token: access_token, oauthTokenScope: oauthTokenScope, expires_in: expires_in} = authResult;
7731
- return Object.assign(Object.assign({
7732
- id_token: id_token,
7733
- token_type: token_type,
7734
- access_token: access_token
7735
- }, oauthTokenScope ? {
7736
- scope: oauthTokenScope
7737
- } : null), {
7738
- expires_in: expires_in
7747
+ throw error;
7748
+ }
7749
+ }
7750
+ _isInteractiveError(error) {
7751
+ return error instanceof MfaRequiredError || error instanceof GenericError && this._isIframeMfaError(error);
7752
+ }
7753
+ _isIframeMfaError(error) {
7754
+ return error.error === "login_required" && error.error_description === MFA_STEP_UP_ERROR_DESCRIPTION;
7755
+ }
7756
+ async _handleInteractiveErrorWithPopup(options) {
7757
+ try {
7758
+ await this.loginWithPopup({
7759
+ authorizationParams: options.authorizationParams
7739
7760
  });
7740
- }));
7761
+ const entry = await this._getEntryFromCache({
7762
+ scope: options.authorizationParams.scope,
7763
+ audience: options.authorizationParams.audience || DEFAULT_AUDIENCE,
7764
+ clientId: this.options.clientId
7765
+ });
7766
+ if (!entry) {
7767
+ throw new GenericError("interactive_handler_cache_miss", "Token not found in cache after interactive authentication");
7768
+ }
7769
+ return entry;
7770
+ } catch (error) {
7771
+ throw error;
7772
+ }
7741
7773
  }
7742
7774
  async getTokenWithPopup() {
7743
7775
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -7844,9 +7876,12 @@
7844
7876
  }));
7845
7877
  } catch (e) {
7846
7878
  if (e.error === "login_required") {
7847
- this.logout({
7848
- openUrl: false
7849
- });
7879
+ const shouldSkipLogoutForMfaStepUp = e instanceof GenericError && this._isIframeMfaError(e) && this.options.interactiveErrorHandler === "popup";
7880
+ if (!shouldSkipLogoutForMfaStepUp) {
7881
+ this.logout({
7882
+ openUrl: false
7883
+ });
7884
+ }
7850
7885
  }
7851
7886
  throw e;
7852
7887
  }