我想说,您的印象太乐观了 :)
迄今为止,对于特定 IdP 的实施来说,这是相当实验性的和可选的。根据规范:此参数将acr
声明请求为自愿声明。
Identityserver 所做的是acr_values
参数解析和有限处理。
根据他们的文档:
允许传入额外的身份验证相关信息
IdentityServer 特殊情况下,以下专有信息acr_values
:
idp:name_of_idp绕过登录/主域屏幕并将用户直接转发到选定的身份提供者(如果每个客户端配置允许)
tenant:name_of_tenant可用于传递登录 UI 的租户名称
您可以通过以下方式发送任意数量的空格分隔值:
&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()