【问题标题】:Identity Server 4 Implicit Flow - Unknown ErrorIdentity Server 4 隐式流 - 未知错误
【发布时间】:2021-06-29 22:54:10
【问题描述】:

我有一个在 .NET 5 上运行的 Identity Server 4 以及一个使用 oidc-client.js 库的简单 JS SPA 客户端

问题是我无法让我的身份服务器使用隐式身份验证。 我的 SPA 客户端在 https://localhost:44334 上运行,Identity Server 在 https://localhost:5005 上运行

当我点击登录时,我正在尝试使用 oidc-client.js 从 IdentityServer 获取令牌

  var config = {
        authority: "https://localhost:5005",
        client_id: "react-client",
        redirect_uri: "https://localhost:44334/callback.html",
        response_type: "id_token token",
        scope: "openid profile Api1",
        post_logout_redirect_uri: "https://localhost:44334/index.html",
    };
    var mgr = new Oidc.UserManager(config);


    mgr.getUser().then(function (user) {
        if (user) {
            log("User logged in", user.profile);
        }
        else {
            log("User not logged in");
        }
    });

    function login() {
        mgr.signinRedirect();
    }

这是我在 Identity Server 上的客户端配置

 return new IdentityServer4.Models.Client
                {
                    ClientId = "react-client",
                    ClientName = "React Client",
                    AllowedGrantTypes = GrantTypes.Implicit,
                    AllowAccessTokensViaBrowser = true,

                    RedirectUris = { "https://localhost:44334/callback.html" },
                    PostLogoutRedirectUris = { "https://localhost:44334/index.html" },
                    AllowedCorsOrigins = { "https://localhost:44334" },

                    AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        "Api1"
                    }
                };

现在的问题是,当我单击登录按钮时,浏览器会重定向到 IdentityServer,但随后会显示此错误。

我做错了什么?

【问题讨论】:

    标签: c# .net asp.net-core oauth identityserver4


    【解决方案1】:

    我发现了问题并解决了。 问题是 Api1 未在 Identity Server 的 ApiScopes 配置中列出。 IdentityServer 显示的错误非常笼统,无法解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 2019-04-26
      • 2020-03-15
      • 1970-01-01
      • 2019-07-25
      • 2018-01-19
      相关资源
      最近更新 更多