c# - IdentityServer4 不为身份令牌调用 GetProfileDataAsync,只为访问令牌调用

使用 IdentityServer 4 (4.1.2),我添加了一个实现 IProfileService 接口的类。 GetProfileDataAsync 方法应该被调用多次(对于每个令牌),但我的方法只为访问令牌(ClaimsProviderAccessToken)调用。

public class LocalUserProfileService : IProfileService
  {
    private readonly IIdentityProviderUserService _identityProviderUserService;

    public LocalUserProfileService(IIdentityProviderUserService identityProviderUserService)
    {
      _identityProviderUserService = identityProviderUserService ??
        throw new ArgumentNullException(nameof(identityProviderUserService));
    }
    public async Task GetProfileDataAsync(ProfileDataRequestContext context)
    {
      var subjectId = context.Subject.GetSubjectId();
      var claims = (await _identityProviderUserService.GetUserClaimsBySubjectAsync(subjectId)).ToList();
      
      Debug.WriteLine($"Adding claims to {context.Caller}");
      context.IssuedClaims.AddRange(claims);
      
    }

    public async Task IsActiveAsync(IsActiveContext context)
    {
      var subjectId = context.Subject.GetSubjectId();
      context.IsActive = await _identityProviderUserService.IsUserActiveAsync(subjectId);
    }
  }

我可以设法只使用我的访问令牌来获取自定义声明,但我想知道为什么不为 identity_token 调用代码,因为我更喜欢在两个令牌中都有声明。

回答1

您是否将 https://docs.duendesoftware.com/identityserver/v5/reference/models/client/ 标志设置为 true?否则,ID 令牌的声明将通过 UserInfo 端点提供。

减小 ID-token 大小的常用方法是不在 ID-token 中包含所有声明。大令牌也会导致大会话 cookie。默认情况下,令牌存储在会话 cookie 中。

相似文章

随机推荐

最新文章