【发布时间】:2020-06-08 10:45:03
【问题描述】:
我正在将 IdentityServer4 与外部提供商 (Google Auth) 一起使用。如何在成功登录 Google 的基础上生成访问令牌?我想注入我自己的声明。
【问题讨论】:
标签: asp.net-core oauth-2.0 identityserver4 openid-connect
我正在将 IdentityServer4 与外部提供商 (Google Auth) 一起使用。如何在成功登录 Google 的基础上生成访问令牌?我想注入我自己的声明。
【问题讨论】:
标签: asp.net-core oauth-2.0 identityserver4 openid-connect
如果在 Identity Server 中实现外部登录(Google Auth),Identity server 从外部 provider 接收到 id token 后,会解码 token 并获取用户的 claim ,登录 user ,然后创建 Identity server 自己的 token 最后返回您的客户端应用程序。
如果你想添加自定义cliams来访问Identity Server颁发的令牌,你可以实现IProfileService:
public class MyProfileService : IProfileService
{
public MyProfileService()
{ }
public Task GetProfileDataAsync(ProfileDataRequestContext context)
{
var claims = new List<Claim>()
{
new Claim("TestKey", "TestValue")
};
context.IssuedClaims.AddRange(claims);
return Task.CompletedTask;
}
public Task IsActiveAsync(IsActiveContext context)
{
// await base.IsActiveAsync(context);
return Task.CompletedTask;
}
}
在 DI 注册:
services.AddTransient<IProfileService, MyProfileService>();
【讨论】:
IProfileService