首页 > 解决方案 > 缺少 WSO2 API JWT 角色

问题描述

我们正在使用 WSO2 API Manager 2.5 版和 Identity Server 5.6,其中 IS 是 API Manager 的密钥管理器。

我在 IS 配置中启用了 JWT。添加了带有用户 ID 和角色的自定义声明方言(因为我们不需要本地声明包含的所有内容,并且由于标头太大而导致后端错误)

当我调用 API 时,会生成并传递 JWT。但是 - 角色声明不适用于我的自定义方言。当我为 JWT 使用本地声明方言时,角色包含在令牌中。

我的配置:

 <JWTConfiguration>
    <JWTHeader>X-JWT-Assertion</JWTHeader
    <JWTGeneratorImpl>org.wso2.carbon.apimgt.keymgt.token.JWTGenerator</JWTGeneratorImpl>
    <ClaimsRetrieverImplClass>org.wso2.carbon.apimgt.impl.token.DefaultClaimsRetriever</ClaimsRetrieverImplClass>
    <ConsumerDialectURI>http://ourdomain.com/jwt</ConsumerDialectURI>
    <SignatureAlgorithm>SHA256withRSA</SignatureAlgorithm>
    <EnableJWTGeneration>true</EnableJWTGeneration>
</JWTConfiguration>

http://ourdomain.com/jwt方言如下所示:

http://ourdomain.com/jwt/uid
    Claim URI   http://ourdomain.com/jwt/uid
    Mapped Local Claim  http://wso2.org/claims/our/uid
http://ourdomain.com/jwt/fullname
    Claim URI   http://ourdomain.com/jwt/fullname
    Mapped Local Claim  http://wso2.org/claims/fullname
http://ourdomain.com/jwt/accountNr
    Claim URI   http://ourdomain.com/jwt/accountNr
    Mapped Local Claim  http://wso2.org/claims/accountNr
http://ourdomain.com/jwt/role
    Claim URI   http://ourdomain.com/jwt/role
    Mapped Local Claim  http://wso2.org/claims/role 

这是生成的 JWT 内容:

{
  "http://ourdomain.com/jwt/version": "1.0.0",
  "http://ourdomain.com/jwt/applicationid": "90",
  "http://ourdomain.com/jwt/keytype": "SANDBOX",
  "http://ourdomain.com/jwt/uid": "123",
  "http://ourdomain.com/jwt/enduser": "mail.address@ourdomain.com@carbon.super",
  "http://ourdomain.com/jwt/subscriber": "EXTERNAL/subscriber@ourdomain.com",
  "iss": "wso2.org/products/am",
  "http://ourdomain.com/jwt/fullname": "Mail Address",
  "http://ourdomain.com/jwt/applicationtier": "Unlimited",
  "http://ourdomain.com/jwt/applicationname": "application",
  "http://ourdomain.com/jwt/enduserTenantId": "-1234",
  "http://ourdomain.com/jwt/tier": "Unlimited",
  "http://ourdomain.com/jwt/usertype": "APPLICATION_USER",
  "http://ourdomain.com/jwt/accountNr": [
    "123451",
    "123452",
    "123453"
  ],
  "http://ourdomain.com/jwt/apicontext": "/heimdall/1.0.0",
  "exp": 1541605849
}

有什么线索我弄错了吗?我是否必须编写自定义令牌生成器?

标签: wso2jwtwso2iswso2-am

解决方案


推荐阅读