asp.net – 如何指定现有的ClaimsIdentity的目的地?
发布时间:2020-12-16 07:20:25 所属栏目:asp.Net 来源:网络整理
导读:我正在使用下面的代码在OpenIdConnectServerProvider.AuthorizationProvider中创建一个ClaimIdentity.但是identity.Name不是searlized.如何让OpenIdConnectServer serarlize这个名字?谢谢. 上一个问题在这里是How to create a ClaimIdentity in asp.net 5 v
我正在使用下面的代码在OpenIdConnectServerProvider.AuthorizationProvider中创建一个ClaimIdentity.但是identity.Name不是searlized.如何让OpenIdConnectServer serarlize这个名字?谢谢.
上一个问题在这里是How to create a ClaimIdentity in asp.net 5 var user = await userManager.FindByNameAsync(context.UserName); var factory = context.HttpContext.RequestServices.GetRequiredService<IUserClaimsPrincipalFactory<ApplicationUser>>(); var identity = await factory.CreateAsync(user); context.Validated(new ClaimsPrincipal(identity)); 解决方法
为避免泄露机密数据,AspNet.Security.OpenIdConnect.Server拒绝序列化未明确指定目标的声明.
要序列化名称(或任何其他声明),您可以使用.SetDestinations扩展名: var principal = await factory.CreateAsync(user); var name = principal.FindFirst(ClaimTypes.Name); if (name != null) { // Use "id_token" to serialize the claim in the identity token or "access_token" // to serialize it in the access token. You can also specify both destinations. name.SetDestinations(OpenIdConnectConstants.Destinations.AccessToken,OpenIdConnectConstants.Destinations.IdentityToken); } context.Validate(principal); 添加声明时,您还可以使用带有目标参数的AddClaim扩展: identity.AddClaim(ClaimTypes.Name,"Pinpoint",OpenIdConnectConstants.Destinations.AccessToken,OpenIdConnectConstants.Destinations.IdentityToken); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Asp.net核心2采用角度6模板
- ASP.NET网络表单的Nancy路由
- 在ASP.Net应用程序中执行Server.MapPath的最有效的方法是什
- asp.net – 在Visual Studio中查找CSS类引用的快捷方式?
- asp.net – “HttpContext.Current.Session”vs Global.asa
- asp.net-mvc-3 – 如何在ASP MVC3中创建可重用的导航菜单?
- asp.net-mvc – Orchard,基于插件的架构,设计模式
- asp.net – MVC – 用户必须在IIS Recycle上重新认证
- asp.net-mvc – 允许asp.net mvc 2控制器名称的URL中的连字
- asp.net-mvc – 使用ASP.NET MVC的Piranha CMS路由问题