【发布时间】:2022-01-22 21:30:18
【问题描述】:
我有一个带有 Angular 的 .net core web api 应用程序。我使用 AspNetCore Identity。我有一个带有 userId 和 value 列的声明表。从 Angular 站点调用 createnewuser 方法,它们调用注册用户方法。这里没有任何问题。
我想将新声明添加到 httpcontext current user claims 列表中。
我试过了,但对我没有帮助。
但是当使用新令牌重新进行身份验证时,我可以看到在 _httpContext.HttpContext.User.Claims 中添加了新声明。如何查看将新声明添加到当前身份 (_httpContext.HttpContext.User.Claims)?
我从 httpontext 获得了当前用户 ID 值。
var parentId = _httpContext.HttpContext.User.Claims?.FirstOrDefault(p => p.Type == "uid");
if (parentId != null && parentId.Value != null)
{
await _IdentityService.AddClaimAsync(new RegisterRequest()
{
"newclaim" = "new-claim-key",
userId = parentId.Value
});
【问题讨论】:
标签: asp.net-core asp.net-core-webapi identityserver4 claims-based-identity