无效范围 Swagger 和 IdentityServer4
Invalid scope Swagger and IdentityServer4
在通过 swaggerui 授权后,我在 IdentityServer4 中不断收到无效范围错误
我试过使用这些配置
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 scope.I 不断获取无效范围。
我错过了什么?
您需要确保 webapi
是一个有效的 API 资源范围。您很可能还没有配置此 API 资源。将以下内容添加到您的 API 资源配置信息存储在 Identity Server 4 端的任何位置。
new ApiResource("webapi", "My API");
在通过 swaggerui 授权后,我在 IdentityServer4 中不断收到无效范围错误
我试过使用这些配置
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 scope.I 不断获取无效范围。 我错过了什么?
您需要确保 webapi
是一个有效的 API 资源范围。您很可能还没有配置此 API 资源。将以下内容添加到您的 API 资源配置信息存储在 Identity Server 4 端的任何位置。
new ApiResource("webapi", "My API");