首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >静默续费返回OAuthErrorEvent{类型:"silent_refresh_timeout",原因: null,参数: null}

静默续费返回OAuthErrorEvent{类型:"silent_refresh_timeout",原因: null,参数: null}
EN

Stack Overflow用户
提问于 2021-04-01 17:21:48
回答 1查看 246关注 0票数 0

在静默续订时调用连接/授权端点之后,它将调用silent_renew.html。但在日志中,它返回OAuthErrorEvent{类型:"silent_refresh_timeout",原因: null,参数: null}

我有一个angular客户。使用silent_renew.html

代码语言:javascript
复制
<!DOCTYPE html>
<html>
  <head>
    <base href="./" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>silent-renew</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  </head>
  <body>
    <script>
      window.onload = function () {
        console.log("Testing" + Date.now());
           parent.postMessage(location.hash, location.origin);
      };
    </script>
  </body>
</html>

identity server中的客户端设置为

代码语言:javascript
复制
new Client
                    {
                        ClientId = app.ClientId,
                        ClientName = app.ClientName,
                        AllowedGrantTypes = GrantTypes.Code,
                        RequirePkce = true,
                        RequireClientSecret = false,
                        AlwaysSendClientClaims = true,
                        AllowOfflineAccess = true,
                        AllowAccessTokensViaBrowser = true,
                        AlwaysIncludeUserClaimsInIdToken = false,
                        RequireConsent = false,
                        AllowRememberConsent = true,
                        EnableLocalLogin = false,
                        IdentityProviderRestrictions = new List<string> {
                        app.Restrictions
                    },
                        AccessTokenLifetime = 60,
                        RedirectUris =
                    {
                        $"{configuration["localAddress"]}",
                        $"{configuration["localAddress"]}/index.html",
                        $"{configuration["localAddress"]}/callback.html",
                        $"{configuration["localAddress"]}/silent-renew.html",

                        app.ClientAddress,
                        app.ClientAddress + "/index.html",
                        app.ClientAddress + "/callback.html",
                        app.ClientAddress + "/silent-renew.html"
                    },

                        PostLogoutRedirectUris =
                    {
                        $"{configuration["localAddress"]}",
                        $"{configuration["localAddress"]}/index.html",
                        app.ClientAddress,
                        app.ClientAddress + "/index.html"
                    },

                        AllowedCorsOrigins =
                    {
                        $"{configuration["localAddress"]}",

                        app.ClientAddress
                    },

                        AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        IdentityServerConstants.StandardScopes.Email,
                        app.ClientCode.ToLower()
                    }
                    });

我已经花了几天的时间试图找到问题所在,所以任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-03 21:50:36

如果任何人遇到同样的问题,这里就是对我有效的解决方案。我对silent_renew.html使用了错误的设置。我用下面的代码替换了它,我从这个链接link得到了它,它起作用了。

代码语言:javascript
复制
<html>
  <body>
    <script>

      const checks = [
        /[\?|&|#]code=/,
        /[\?|&|#]error=/,
        /[\?|&|#]token=/,
        /[\?|&|#]id_token=/,
      ];

      function isResponse(str) {
        let count = 0;

        if (!str) {
          return false;
        }

        for (let i = 0; i < checks.length; i++) {
          if (str.match(checks[i])) return true;
        }

        return false;
      }

      let message = isResponse(location.hash)
        ? location.hash
        : "#" + location.search;

      console.log(
        "Silent refresh iframe is posting to the parent application, message:",
        message
      );

      (window.opener || window.parent).postMessage(message, location.origin);
    </script>
  </body>
</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66901824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档