在身份验证挑战期间,我希望向inside 4发送一个acr值,并让它在登录后的重定向返回时在id_token中返回。
从我在网上读到的,我得到的印象是,这是使用acr值的一种常见方式。
对于这个acr值没有什么特殊的IS4需要处理,只需要返回它,所以我可以使用身份验证提供者在站点上使用它。
在调用context.ProtocolMessage.AcrValues回调时,我确实通过设置RedirectToIdentityProvider成功地发送了它,而IS4确实得到了它,但是在id_token中没有任何返回。
我是否需要为acr包括在id_token中做一些特别的事情?我应该以某种方式手动添加吗?任何代码样本都将不胜感激。
发布于 2022-02-18 15:18:58
我想说,你有一个过于乐观的印象:)
到目前为止,这只是实验性的,对于特定的国内流离失所者来说是可选的。根据等级库:acr索赔是根据这个参数作为自愿索赔请求的。
Identityserver所做的是acr_values参数解析和有限处理。
根据他们的文档
允许传递其他身份验证相关信息。 IdentityServer特例--以下专有
acr_values: idp:name_of_idp绕过登录/主域屏幕,将用户直接转发给所选的身份提供程序(如果允许的话) 可以使用tenant:name_of_tenant将租户名称传递给登录用户界面。
您可以按照以下方式发送任意多个空格分隔的值:
&acr_values=param1:value1 param2:value2 tenant:name_of_tenant idp:name_of_idp
然后使用以下访问器在Identityserver端执行任何自定义处理:
var ctx = _IIdentityServerInteractionService.GetAuthorizationContextAsync(returnUrl);
IEnumerable<string> acrs = ctx.AcrValues;
string tenant = ctx.Tenant;
string idp = ctx.IdP;当您想通知客户端他们的acr_values已经被处理时,您可以像其他任何用户声明一样添加acr:
调用时,首先将其添加到Identityserver中的会话中
await HttpContext.SignInAsync(identityServerUser, props);
// Where identityServerUser can take additional claims. 之后,您的自定义声明在Subject中。
将其添加到id_token的一种方法是按照描述的IProfileService实现这里。
public Task GetProfileDataAsync(ProfileDataRequestContext context)
{
context.AddRequestedClaims(context.Subject.Claims);
if (context.Caller == "ClaimsProviderIdentityToken")
{
var acr = context.Subject.Claims.FirstOrDefault(c=>c.Type=="acr");
if(acr != null)
context.IssuedClaims.Add(acr);
}
return Task.CompletedTask;
}另一种方法是在启动时将声明添加到IdentityResources.OpenId方法中的GetIdentityResources()范围中。openid是唯一的强制范围,因此声明将跳到带有默认AddRequestedClaims()实现的令牌中。
https://stackoverflow.com/questions/71159908
复制相似问题