美文网首页
Identity Server 4 学习(十一)access_t

Identity Server 4 学习(十一)access_t

作者: 寻找无名的特质 | 来源:发表于2021-11-17 05:47 被阅读0次

使用Identity Server登录的客户端,访问被Identity Server保护的API时,通过bearer和access_token访问API,在API端可以使用User.Claim获取Claims信息:

namespace MyWebApi.Controllers
{
    [Route("identity")]
    [Authorize]
    public class IdentityController : ControllerBase
    {
        [HttpGet]
        public IActionResult Get()
        {
            var claims = User.Claims.ToList();
            return new JsonResult(from c in User.Claims select new { c.Type, c.Value });
        }
    }
}

但是会发现,不是所有的Claim都包括在access_token传递过来,只包括客户端id等少数系信息。如果希望包括更多的User Claim信息,需要在Api Resources中显示定义。


图片.png

相关文章

网友评论

      本文标题:Identity Server 4 学习(十一)access_t

      本文链接:https://www.haomeiwen.com/subject/vfabzltx.html