【问题标题】:When renewing id_token via refresh_token in Auth0, jti (JWT ID) not in new id_token在 Auth0 中通过 refresh_token 更新 id_token 时,jti (JWT ID) 不在新的 id_token 中
【发布时间】:2016-12-15 20:00:16
【问题描述】:

登录 Auth0 时:

POST https://my.auth0.com/oauth/ro
{
  "client_id":   "<client-id>",
  "username":    "me@gmail.com",
  "password":    "••••••••",
  "connection":  "<auth0-connection>",
  "grant_type":  "password",
  "scope":       "openid offline_access jti email",
  "device":      "<device-id>"
}
// Response
{
  "refresh_token": "<refresh-token>",
  "id_token": "<id-token>",
  "access_token": "<access-token>",
  "token_type": "bearer"
}
// id_token JWT payload
{
  "jti": "3d4c5e97-3543-4c53-b46e-3aa965cd5a34",
  "email": "me@gmail.com",
  "email_verified": false,
  "iss": "https://my.auth0.com/",
  "sub": "auth0|<id>",
  "aud": "<aud>",
  "exp": 1481766419,
  "iat": 1481730461
}

如果我在我的作用域中指定jti,则返回的id_token(JWT)将包含jti。 Auth0 建议在 JWT 中使用 jtijtis 唯一标识 JWT,可用于将 JWT 列入黑名单。

但由于某种原因,如果我尝试使用刷新令牌获取新的 id_token

POST https://my.auth0.com/delegation
{
  "client_id":       "<client-id>",
  "grant_type":      "urn:ietf:params:oauth:grant-type:jwt-bearer",
  "refresh_token":   "<refresh-token>",
  "api_type":        "app",
  "scope":           "openid offline_access jti email",
  "device":          "<device-id>"
}
// Response
{
  "token_type": "Bearer",
  "expires_in": 35958,
  "id_token": "<id-token>"
}
// id_token JWT payload
{
  "email": "me@gmail.com",
  "email_verified": false,
  "iss": "https://my.auth0.com/",
  "sub": "auth0|<id>",
  "aud": "<aud>",
  "exp": 1481766678,
  "iat": 1481730720,
  "azp": "<azp>"
}

即使我在我的范围内指定了jti,返回的id_token 也不包含jti

这是一个错误吗?请帮忙。

【问题讨论】:

    标签: auth0 refresh-token


    【解决方案1】:

    默认情况下不会生成或包含jti 声明。如果您看到这种行为,最可能的解释是您有一个执行以下操作的自定义规则:

    function (user, context, callback) {
      user.jti = require('uuid').v4();
      callback(null, user, context);
    }
    

    这意味着,当您将 jti 作为范围包含时,该值将包含在生成的 ID 令牌中,因为它是从该属性获得的。在通过委托时,jti 声明似乎得到了特殊处理,并且在您进行刷新时被忽略。不鼓励使用委托进行刷新,但是,如果您想继续使用该方法并且只需要 JWT 中的唯一标识符,如果您使用非保留的声明名称,则可以解决此问题。例如,在规则中:

    function (user, context, callback) {
      user.myjti = require('uuid').v4();
      callback(null, user, context);
    }
    

    然后在两个请求上都包含myjti 范围;快速测试表明,这在使用委托时也有效。

    【讨论】:

    • 谢谢!你是对的,有一个规则设置 jti。我应该使用什么端点来使用我的 refresh_token 获取新的 id_token?我用 {grant_type:"refresh_token",refresh_token:} 尝试了dev-innit.auth0.com/oauth/token,但我得到了 unsupported_grant_type。我宁愿使用正确的端点,也不愿创建自己的 JWT ID 属性。
    • 要使用/oauth/tokenrefresh_token 的授权类型,您需要在高级帐户设置中启用OAuth 2.0 API 授权,然后还可以启用客户端应用程序级别的 OIDC Conformant 标志。但是,尽管这样做了,但我认为在通过令牌端点刷新时当前不支持规则,因此您将无法将声明添加到值中。目前,自定义声明名称和委托端点的使用是可用的。
    • 谢谢,这真的很清楚,很直接。我将使用/delegation 端点,然后直到/oauth/token 支持自定义声明。
    猜你喜欢
    • 2017-07-25
    • 2017-06-02
    • 2019-12-08
    • 2017-02-03
    • 2014-11-21
    • 2017-03-31
    • 2020-07-08
    • 2017-05-19
    • 2015-02-01
    相关资源
    最近更新 更多