【发布时间】:2021-09-10 13:34:52
【问题描述】:
我正在尝试使用超级管理员 (superadmin) 来模拟用户 (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 '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>'
- 使用上述令牌,我得到了模拟用户的 (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