【问题标题】:why am i getting role claims sometimes namespaced and sometimes without namespace为什么我得到的角色声明有时带有命名空间,有时却没有命名空间
【发布时间】:2018-11-22 18:33:57
【问题描述】:

我正在使用 IdentityServer4 进行身份验证。一些客户端使用引用令牌,一些客户端使用自包含令牌。

  • 对于参考令牌,我使用 IntrospectionClient 来交换 声明的访问令牌。
  • 对于自包含令牌,我使用“JwtSecurityTokenHandler.ValidateToken”将 accesstoken 交换为声明。

首先我获得了带有键“role”的角色声明,第二个我获得了带有密钥“http://schemas.microsoft.com/ws/2008/06/identity/claims/role”的角色声明

知道如何将这两种情况都排成一个键吗?

【问题讨论】:

    标签: jwt access-token identityserver4


    【解决方案1】:

    您并不是说您的“自包含”客户端使用什么技术,但我假设它是一些 .NET。

    以下是解决方案:

    .NET 核心:

    在您的Startup.cs(客户项目的)中添加以下行:

    JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
    

    Documentation 用于 .NET Core。

    .NET 框架:

    再次在Startup.cs 中添加以下内容:

    AntiForgeryConfig.UniqueClaimTypeIdentifier = Constants.ClaimTypes.Subject;
    JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
    

    Documentation 用于 .NET Framework。

    这应该可以解决您的问题,并且您的所有声明都将带有短名称。

    【讨论】:

      猜你喜欢
      • 2013-01-10
      • 1970-01-01
      • 2011-12-10
      • 1970-01-01
      • 2018-03-09
      • 1970-01-01
      • 2015-11-21
      • 2023-03-06
      • 2011-08-23
      相关资源
      最近更新 更多