auth0-spa-js间歇性无效状态

时间:2020-07-01 17:25:35

标签: authentication auth0

我们正在使用auth0-spa-js。 当用户键入我们的网址时,将加载应用程序, 使用createAuth0Client创建auth0实例 并使用loginWithRedirect启动登录

这将重定向到auth0并显示登录提示。 根据JavaScript SPA的auth0示例,输入有效的凭证并将处理返回到我们的应用程序时,逻辑将在查询参数中查找code =和state =。

这将调用handleRedirectCallback,该失败将因“无效状态”错误

如果将初始URL重新输入到浏览器地址栏中,循环将重新开始,但是这次不提示用户登录,auth0重定向回到我们的网站 这将再次命中code =和state =代码检查,从而调用handleRedirectCallback 但这次用户已通过身份验证并登录

这仅适用于部分用户,而不是全部。我们看不到模式。

其他人有没有经历过?


    async function authenticate() {
    
      auth0 = await createAuth0Client(config);
    
      // eslint-disable-next-line no-async-promise-executor
      return new Promise(async resolve => {
        try {
          const isAuth = await auth0.isAuthenticated();
          const query = window.location.search;
          if (isAuth) {
            resolve(auth0);
          } else if (query.includes(ERROR_DESCRIPTION)) {
            throw new Error(decodeURI(getQueryParameter(ERROR_DESCRIPTION)));
          } else if (query.includes("code=") && query.includes("state=")) {
            await auth0.handleRedirectCallback();
            resolve(auth0);
          } else {
            await auth0.loginWithRedirect({
              redirect_uri: config.redirect_uri
            });
          }
        } catch (e) {
          log(e);
        }
      });
    }

0 个答案:

没有答案