如何为机器对机器应用程序类型向分配了 auth0 的 JWT 添加声明?

How can I add claims to a JWT assigned with auth0 for a machine-to-machine application type?

我使用 auth0 作为单点登录的 OIDC 提供商。

到目前为止,我尝试使用两种应用程序类型登录,一方面是 native 应用程序类型,另一方面是 machine-to-machine 应用程序类型。

但是,当我登录时,我只收到一个非常简单的 id_token,其中包含以下负载:

{
  "https://example.com/roles": [
    "user"
  ],
  "iss": "https://my.idp.provider.com",
  "sub": "oauth2|someconnection|samlp|somecompany|someusername",
  "aud": "REMOVED",
  "iat": 1547652649,
  "exp": 1547688649
}

我想向此令牌添加 group 声明。如何配置我的 Auth0 租户以将 "group": "admin" 添加为声明?我是否需要在我的身份验证客户端中启用特定的 scope 才能接收 groups 声明?

我已经在 auth0 中安装并配置了 授权扩展 ,但这对我的令牌中的声明没有任何影响。我知道 Authorization Extension 不支持机器对机器的应用程序。因此,我添加了本机应用程序并尝试使用它登录,但也没有 return 任何其他声明。

配置授权扩展后,您可以将自定义声明添加到规则中颁发的 JWT 令牌。这里有一个示例规则可以完成这项工作:https://auth0.com/docs/extensions/authorization-extension/v2/rules#add-custom-claims-to-the-issued-token

您也可以使用 Hook 自定义客户端凭据令牌:https://auth0.com/docs/api-auth/tutorials/client-credentials/customize-with-hooks

编辑:符合 OIDC 标准的应用程序要求您定义命名空间,因为角色和组等授权数据不是 OIDC 声明。