【问题标题】:How to add user attribute values to token when impersonating in Keycloak在 Keycloak 中模拟时如何将用户属性值添加到令牌
【发布时间】:2021-09-10 13:34:52
【问题描述】:

我正在尝试使用超级管理员 (superadmin) 来模拟用户 (tony123)。我遵循的步骤如下。

  1. 获取超级管理员的访问令牌,如下所示。
curl --location --request POST 'http://localhost:8180/auth/realms/tenant/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=superadmin' \
--data-urlencode 'password=<superadmin-password>' \
--data-urlencode 'client_id=<source-client-id>' \
--data-urlencode 'client_secret=<source-client-secret>'
  1. 使用上述令牌,我得到了模拟用户的 (tony123) 令牌,如下所示。
curl --location --request POST 'http://localhost:8180/auth/realms/tenant/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=<source-client-id>' \
--data-urlencode 'client_secret=<source-client-secret>' \
--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
--data-urlencode 'subject_token=<access token got in step one>' \
--data-urlencode 'requested_token_type=urn:ietf:params:oauth:token-type:access_token' \
--data-urlencode 'requested_subject=<user id of tony123>'

按照上述两个步骤,我可以得到正确的模拟令牌。此模拟令牌仅包含令牌中 tony123 的preferred_username 和email 属性。我想通过从用户属性映射中添加一些phone_number 来进一步自定义模拟令牌。我做不到。

我尝试在 Keycloak 管理员的 source-client 中为 phone_number 添加映射器。这是一次不成功的尝试。如何做到这一点?

【问题讨论】:

    标签: spring-boot keycloak impersonation keycloak-services keycloak-rest-api


    【解决方案1】:

    首先创建自定义属性,然后在客户端映射器中,添加具有用户属性类型的令牌映射器。

    看看这个page。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      • 1970-01-01
      • 2017-10-24
      • 2020-10-09
      • 1970-01-01
      • 2021-11-23
      • 2018-07-15
      相关资源
      最近更新 更多