Identity Server 4 SignInAsync中的其他LocalClaims的目的是什么

问题描述 投票:0回答:1

在Identity Server 4中,快速入门,ExternalController.cs-CallBack方法,我发现以下内容:

// this allows us to collect any additonal claims or properties
// for the specific prtotocols used and store them in the local auth cookie.
// this is typically used to store data needed for signout from those protocols.
var additionalLocalClaims = new List<Claim>();
var localSignInProps = new AuthenticationProperties();
ProcessLoginCallbackForOidc(result, additionalLocalClaims, localSignInProps);

// issue authentication cookie for user
await HttpContext.SignInAsync(user.SubjectId, user.Username, provider, localSignInProps, additionalLocalClaims.ToArray());

您可以在此链接上查看完整的代码集-IdentityServer4.Quickstart.UI

我尝试通过以下操作向该additionalLocalClaims列表添加一些声明:

additionalLocalClaims.Add(new Claim("TestName", "TestValue"));

但是即使ApiResource中包含ClaimType“ TestName”,它也不会出现在UserClaims或AccessToken中。

我想在AccessToken中为Google身份验证添加一些自定义声明/值,我认为AdditionalLocalClaims是附加其他声明的正确选择。

P.S。我终于实现了IProfileService并可以返回其他声明。但是我仍然想知道additionalLocalClaims扩展方法中该HttpContext.SignInAsync的用例。

asp.net-core identityserver4 claims
1个回答
0
投票

ASP.NET Core的HttpContext上有一些与身份验证相关的扩展方法,用于发出身份验证cookie并在其中登录用户,您可以向cookie添加Identity 4的自定义气候以用于Identity Server 4的身份验证会话。例如,您可以添加声明需要注销的声明,某些外部身份提供商可能会发出会话ID声明,您可以通过additionalLocalClaims将其包含在本地身份验证cookie中,如果用户以您的身份注销,则可以用于从外部身份提供商执行单次注销服务器。但是声明保留在IDS4的本地auth cookie中,它们不在ID令牌,访问令牌和userinfo端点中。您可以按照您所说的将IProfileService实现为在令牌或userinfo端点中涉及自定义声明。

© www.soinside.com 2019 - 2024. All rights reserved.