【发布时间】:2020-01-06 10:46:05
【问题描述】:
我是 Identity Server 4 的新手,我正在努力获取用户 identities。目前,我正在通过 Identity Server 保护的 API 显示 Claims:
namespace API01.Controllers
{
[Route("identity")]
[Authorize]
public class IdentityController : ControllerBase
{
// GET identity
[HttpGet]
public IActionResult Get()
{
return new JsonResult(from c in User.Claims select new { c.Type, c.Value });
}
}
}
问题在于,当我解码 jwt 时,email 资源只是显示为值 email。
"scope": [
"email",
"openid",
"api1"
],
我一直在尝试使用User.Identities,但到目前为止我无法从我的AllowedScopes {"email", "openid", "api1"} 获得所需的信息。
基本上,我想获得在我的情况下为test@test.com 的值。我不担心返回一个JsonResult,现在只要一个字符串就足够了,如果它会很困难的话。
【问题讨论】:
-
添加新用户时,请确认您是否将声明与用户(即 AspNetuserClaims 表)进行映射。
-
是的,但我刚才注意到了一些事情......我正在将
claims映射到users,但我没有使用Claims = new [] { new "claim 1", new "claim 2", ... },我的是Claims = { new "claim 1", new "claim 2", … }。我不确定这是否重要。将在我刚刚阅读文档中的 Quickstart 3 时进行测试。
标签: c# .net asp.net-core identityserver4