java - 在模拟 Keycloak 期间在目标客户端的资源上获取 403
问题描述
我正在尝试user
通过使用另一个用户(超级管理员)来模拟具有角色(tony123)的 Keycloak 用户。
超级管理员具有分配给客户的impersonation
角色realm-management
。
我还可以在源客户端(源客户端)中为超级管理员生成令牌
curl --location --request POST 'http://localhost:8180/auth/realms/mytenant/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=superadmin' \
--data-urlencode 'password=c3VwZXJhZG1pbg==' \
--data-urlencode 'client_id=source-client' \
--data-urlencode 'client_secret=source-client-secret'
我还按照以下步骤将内部令牌设置为内部令牌客户端令牌交换。
- 使用命令行参数运行 Keycloak
-Dkeycloak.profile.feature.admin_fine_grained_authz=enabled -Dkeycloak.profile.feature.token_exchange=enabled
- 在目标客户端中设置令牌交换权限。添加一个基于客户端的策略,并将其
source-client
作为客户端。 Users
在选项卡 上启用权限- 设置
admin-impersonating.permission.users
权限。添加了source-client
作为客户端的基于客户端的策略。
通过上述设置,我可以使用以下 cURL 命令生成模拟令牌
curl --location --request POST 'http://localhost:8180/auth/realms/mytenant/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=source-client' \
--data-urlencode 'client_secret=source-client-secret' \
--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
--data-urlencode 'subject_token=.....' \
--data-urlencode 'requested_token_type=urn:ietf:params:oauth:token-type:access_token' \
--data-urlencode 'audience=target-client' \
--data-urlencode 'requested_subject=<user id of tony123>'
使用我从上面的 cURL 命令获得的 access_token,我现在正在尝试访问能够直接访问的target-client
资源tony123
。当我这样做时,我在通话中被禁止 403。我不确定我在这里缺少什么。提前致谢
解决方案
推荐阅读
- bash - docker-compose.yml 中用于 kafka 的双双花括号
- mysql - 不正确的日期时间值:'DEFAULT' 在 node.js 中使用 mysql
- sql-server - @ThisDB 附近的语法不正确
- text - 24位原始rgb文件的数据结构
- python - 如何计算数据框中的条件密度?
- audio - 有没有办法使用 Google Apps 脚本播放背景音乐?
- zip - 如何在 bazel 中压缩文件
- symfony - 如何以 Symfony 形式制作 RadioButton?
- pandas - 在 DataFrame 中选择多组列
- python - 按时间序列的月份(所有 1 月、所有 2 月等)获取平均值