【问题标题】:Invalid scope Swagger and IdentityServer4无效的范围 Swagger 和 IdentityServer4
【发布时间】:2019-12-05 17:08:28
【问题描述】:

通过 swaggerui 授权后,IdentityServer4 中不断出现 Invalid Scope 错误

我尝试使用这些配置

new Client
{
    ClientId = "swaggerui",
            ClientName = "Swagger UI",
            AllowedGrantTypes = GrantTypes.Implicit,
            AllowAccessTokensViaBrowser = true,

            RedirectUris = {"http://localhost:5001/swagger/oauth2-redirect.html"},
            PostLogoutRedirectUris = {"http://localhost:5001/swagger/"},

            AllowedScopes =
                    {
                            "webapi"
                    }
},

以及swaggerui上的如下配置

c.AddSecurityDefinition("oauth2", new OAuth2Scheme
{
    Type = "oauth2",
            Flow = "implicit",
            AuthorizationUrl = "http://localhost:5000/connect/authorize",
            TokenUrl = "http://localhost:5000/connect/token",
            Scopes = new Dictionary<string, string>
    {
        {
            "webapi", "My API"
        }
    }
});

IdentityServer 识别客户端,但似乎没有获得 webapi 范围。我不断收到无效范围。 我错过了什么?

【问题讨论】:

  • 您是如何在 C# 应用程序中配置 IdentityServer 的?您是否在 IdentityServer 的资源存储中注册了这些自定义范围?如果您还没有,您可以在“AddIdentityServer”之后使用“AddInMemoryApiResources”扩展方法

标签: swagger identityserver4 swagger-ui


【解决方案1】:

您需要确保 webapi 是有效的 API 资源范围。您很可能尚未配置此 API 资源。将以下内容添加到您的 API 资源配置信息存储在 Identity Server 4 端的任何位置。

new ApiResource("webapi", "My API");

【讨论】:

  • 是的,就是这样......谢谢你
猜你喜欢
  • 2021-02-09
  • 2021-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-29
  • 2017-08-20
  • 2019-06-18
相关资源
最近更新 更多