从服务帐户访问用户角色

Access to users roles from a service account

我尝试从服务帐户中获取用户角色,但没有成功。这是我的配置:

realm: realmA
  client: app-a
    roles: ['operator', 'manager']
  user: user-a
    roles on app-a: 'operator'

从其他堆栈问题我知道我需要:

现在我可以向 KC 请求我的 app-a 服务帐户到端点 <KC URL>/realms/realmA/protocol/openid-connect/token 的访问令牌,并使用此访问令牌向该端点请求用户数据 <KC URL>/admin/realms/realmA/users之后我可以检索具有这种形状的用户列表:

[
{
  id: '10f5c814-1474-4ed0-9985-99b928cead3b',
  createdTimestamp: 1646751082376,
  username: 'username',
  enabled: true,
  totp: false,
  emailVerified: true,
  firstName: 'TheName',
  lastName: 'LastName',
  email: 'my@company',
  attributes: { time_intervals: [ '8-13' ] },
  disableableCredentialTypes: [],
  requiredActions: [],
  notBefore: 0,
  access: {
    manageGroupMembership: false,
    view: true,
    mapRoles: false,
    impersonate: false,
    manage: false
  }
}
]

现在我想检查用户 roles 至少是用户在客户端中拥有的角色 app-a 但经过数小时后我无法找到这样做的方法。正确的做法是什么?

Now I want to inspect the users roles at least the roles that the user has inside the client app-a

为此尝试端点:

<KC URL>/realms/realmA/users/<USER ID>/role-mappings/clients/<ID OF THE CLIENT>

在您的情况下,<ID OF THE CLIENT> 将是 app-aid