identityserver4 - 即使添加到客户端,Identity Server 4 中也缺少电子邮件范围
问题描述
我正在使用带有 Angular 客户端的 Identity Server 4。
在双方我都添加相同的范围:
'openid profile offline_access email api'
但是我收到一个错误:
Sorry, there was an error : invalid_scope
Invalid scope
我检查了 Well-Known OpenID 配置,我看到:
"scopes_supported": [
"openid",
"profile",
"api",
"offline_access"
]
所以电子邮件范围不显示?
这可能是问题吗?为什么会这样?
我的 Identity Server 4 客户端定义是:
new Client {
ClientId = "spa",
ClientSecrets = { new Secret("secret".Sha256()) },
AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
RequireClientSecret = false,
AllowAccessTokensViaBrowser = true,
AllowOfflineAccess = true,
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
IdentityServerConstants.StandardScopes.OfflineAccess,
"api"
},
RedirectUris = new List<String> {
"https://localhost:5001",
"https://localhost:5001/index.html",
"https://localhost:5001/silent-refresh.html"
},
PostLogoutRedirectUris = new List<String> {
"https://localhost:5001/"
},
AllowedCorsOrigins = new List<String> {
"https://localhost:5001"
}
}
解决方案
您需要添加一个 IdentityResource:
public static IEnumerable<IdentityResource> GetIdentityResources()
{
return new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
new IdentityResources.Email()
};
}
然后在 startup.cs 中添加:
var identityServerBuilder = services.AddIdentityServer(...)
.AddInMemoryIdentityResources(GetIdentityResources())
推荐阅读
- python - 我需要获取 pandas-dataframe 行,其中包括列中特定列表位置的特定值
- python - 用于任务管道的 Python 模式
- python - PlotlyRequestError:未提供身份验证凭据 python
- angular - 如何精确匹配 Angular 材料表中选择的过滤器字符串数据?
- java - 出现错误后 Spring Boot 应用程序未运行 原因:java.lang.NoClassDefFoundError: org/eclipse/jetty/server/RequestLog$Writer
- javascript - 如何串联。(点)在javascript中带有数字
- javascript - Jquery - 找到父元素,然后在其中选择另一个元素
- c++ - 向量中的 push_back
显示错误 - c# - 如何调用在运行时选择的几个静态类之一的方法?
- google-cloud-platform - gcloud 在验证服务帐户密钥时崩溃并出现错误:gcloud crashed (OperationalError): disk I/O error