【发布时间】:2019-08-30 00:40:11
【问题描述】:
如何从 asp.net 核心项目重新生成 open id connect 自定义声明?
我已经设置了手动映射到声明类型名称,但有时我需要从事件 OnTicketRecieved 之外更新其他声明,即来自控制器,所以在那个阶段我确实需要以某种方式重新生成声明。我通过以下方式设置了 openIdConnect:
_services
.AddAuthentication(options =>
{
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddOpenIdConnect(options =>
{
options.ClientId = clientId;
options.ClientSecret = clientSecret;
options.Authority = $"{baseAuthorityUrl}/{tenantId}";
options.CallbackPath = new PathString(callBackPath);
options.Scope.Add("email");
options.Scope.Add("profile");
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name"
};
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProvider = e =>
{
return Task.CompletedTask;
},
OnTicketReceived = e =>
{
e.Principal.Identities.First().AddClaim(new Claim(ClaimTypes.Name, e.Principal.FindFirstValue("name")));
return Task.CompletedTask;
}
};
})
如何从控制器重新生成声明? 我正在考虑以某种方式覆盖 signInManager.RefreshSignInAsync(user)。
【问题讨论】:
标签: c# asp.net-core asp.net-identity openid-connect