Auth0 JWT 访问令牌

Auth0 JWT Access Tokens

我很难将 Auth0 获取到 JWT 格式的 return 访问令牌。我需要 JWT 格式的它们,以便我可以使用 Java JWT 库验证它们。

我正在使用 Auth0 lock 登录,并使用 /oauth/token 获取访问令牌 - 我尝试将观众设置为我们的 API 标识符(在多个地方,包括锁定身份验证参数和 /oauth/token 有效负载),但没有成功 - 访问令牌是 returned 但不是 JWT。

或者,是否有用于验证 "native" Auth0 访问令牌的 Java 库?

var options = {
    auth: {
        redirectUrl: '<redirect_link>',
        responseType: 'code',
        params: {
            audience: '<API_identifier>',
            scope: 'openid offline_access'
        }
    },
    allowedConnections: ['Username-Password-Authentication']
};

var lock = new Auth0Lock('<clientId>', '<auth0_Host>', options); 
lock.show();

returned 代码用于 POST 到 https://<host>/oauth/token 数据:

client_id=<client_id>&redirect_uri=<redirect_url>&client_secret=<client_secret>&code=<returned_code>&grant_type=authorization_code&audience=<API_identifier>

哪个成功但access token不是JWT,例如:"access_token":"sG99DAJI789SYgTj"

使用 JWT 格式的范围 openid returns 和 id_token,但从阅读文档来看,此令牌不应用于 API 授权。

Auth0 似乎正在使用 OpenID connect,这是 OAuth2 的扩展。最终用户身份验证成功后,服务器 returns JWT 格式的 ID 令牌和访问令牌

ID Token

The ID Token is a security token that contains Claims about the Authentication of an End-User by an Authorization Server when using a Client, and potentially other requested Claims. The ID Token is represented as a JSON Web Token (JWT) [JWT].

您可以使用任何 JWT 库在客户端验证 ID 令牌,但访问令牌的验证规则不同

3.2.2.9. Access Token Validation

To validate an Access Token issued from the Authorization Endpoint with an ID Token, the Client SHOULD do the following:

  1. Hash the octets of the ASCII representation of the access_token with the hash algorithm specified in JWA for the alg Header Parameter of the ID Token's JOSE Header. For instance, if the alg is RS256, the hash algorithm used is SHA-256.

  2. Take the left-most half of the hash and base64url encode it.

  3. The value of at_hash in the ID Token MUST match the value produced in the previous step.

所以,基本上要验证它,您需要使用 ID 令牌的哈希算法计算 access_token 的摘要,并检查它是否与 ID 令牌的 at_hash 声明相匹配