作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我按照文档中的示例编写了一个小型 IdentityServer 演示服务器。我有以下 TestUser
:
new TestUser
{
SubjectId = "1",
Username = "Username",
Password = "password",
Claims = new List<Claim>()
{
new Claim(System.Security.Claims.ClaimTypes.Name, "Username"),
new Claim(System.Security.Claims.ClaimTypes.Email, "username@domain.com")
}
}
我使用 ResourceOwnerPassword
流程获取访问 token 。并且我有权访问我的 API。
问题是,当我在 protected API 中尝试获取用户身份时,名称属性返回为 null,并且我看不到电子邮件声明。无论我做什么,我总是看到同样的 12 条声明。 sub
声明是唯一与我放入 Client
对象中的信息一起传递的声明。
如何填充 HttpContext.User.Identity.Name
属性并发送有关用户的其他声明/数据?
最佳答案
原因可能是您没有为您的客户请求适当的资源/范围。
例如,在 Resources.cs 中,您可以添加要包含在所有 api2 范围中的声明
new ApiResource
{
Name = "api2",
ApiSecrets =
{
new Secret("secret".Sha256())
},
UserClaims =
{
JwtClaimTypes.Name,
JwtClaimTypes.Email
},
Scopes =
{
new Scope()
{
Name = "api2.full_access",
DisplayName = "Full access to API 2",
},
new Scope
{
Name = "api2.read_only",
DisplayName = "Read only access to API 2"
}
}
}
例如在 client.cs 中
new Client
{
ClientId = "roclient",
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
AllowOfflineAccess = true,
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
"custom.profile",
"api1", "api2.read_only"
}
},
关于identityserver4 - IdentitySever4 用户声明和 ASP.NET User.Identity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43629216/
我有一个 asp core angular 2 SPA 网站,它使用 oidc 客户端向 IdenityServer 进行身份验证。 我尝试从 javascript walthrough exampl
我是一名优秀的程序员,十分优秀!