@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.
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.16/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.16.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
@@ -7715,29 +7715,57 @@
7715
7715
  return;
7716
7716
  }
7717
7717
  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;
7718
+ try {
7719
+ return await this.lockManager.runWithLock(lockKey, 5e3, (async () => {
7720
+ if (cacheMode !== "off") {
7721
+ const entry = await this._getEntryFromCache({
7722
+ scope: getTokenOptions.authorizationParams.scope,
7723
+ audience: getTokenOptions.authorizationParams.audience || DEFAULT_AUDIENCE,
7724
+ clientId: this.options.clientId
7725
+ });
7726
+ if (entry) {
7727
+ return entry;
7728
+ }
7727
7729
  }
7730
+ const authResult = this.options.useRefreshTokens ? await this._getTokenUsingRefreshToken(getTokenOptions) : await this._getTokenFromIFrame(getTokenOptions);
7731
+ const {id_token: id_token, token_type: token_type, access_token: access_token, oauthTokenScope: oauthTokenScope, expires_in: expires_in} = authResult;
7732
+ return Object.assign(Object.assign({
7733
+ id_token: id_token,
7734
+ token_type: token_type,
7735
+ access_token: access_token
7736
+ }, oauthTokenScope ? {
7737
+ scope: oauthTokenScope
7738
+ } : null), {
7739
+ expires_in: expires_in
7740
+ });
7741
+ }));
7742
+ } catch (error) {
7743
+ if (this._isInteractiveError(error) && this.options.interactiveErrorHandler === "popup") {
7744
+ return await this._handleInteractiveErrorWithPopup(getTokenOptions);
7728
7745
  }
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
7746
+ throw error;
7747
+ }
7748
+ }
7749
+ _isInteractiveError(error) {
7750
+ return error instanceof MfaRequiredError;
7751
+ }
7752
+ async _handleInteractiveErrorWithPopup(options) {
7753
+ try {
7754
+ await this.loginWithPopup({
7755
+ authorizationParams: options.authorizationParams
7739
7756
  });
7740
- }));
7757
+ const entry = await this._getEntryFromCache({
7758
+ scope: options.authorizationParams.scope,
7759
+ audience: options.authorizationParams.audience || DEFAULT_AUDIENCE,
7760
+ clientId: this.options.clientId
7761
+ });
7762
+ if (!entry) {
7763
+ throw new GenericError("interactive_handler_cache_miss", "Token not found in cache after interactive authentication");
7764
+ }
7765
+ return entry;
7766
+ } catch (error) {
7767
+ throw error;
7768
+ }
7741
7769
  }
7742
7770
  async getTokenWithPopup() {
7743
7771
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};