如何从keycloak中的自定义客户端获取角色?

2024-02-19

为了获得自定义客户端中的角色,我知道我需要执行两个 API。一种是获取访问令牌,一种是获取角色。我的疑问是,我应该通过在标头中发送 admin-CLI 详细信息来获取 accessToken 还是因为我想要我创建的自定义客户端的角色?因为,我在尝试获取角色时收到unknown_error。

获取accessToken:

curl -X POST \
  http://localhost:8080/auth/realms/test-keycloak-example/protocol/openid-connect/token \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'grant_type=client_credentials&client_id=test-keycloak-example&client_secret=shhh'

获取角色:

curl -X GET \
  http://localhost:8080/auth/admin/realms/test-keycloak-example/clients/cb11fd17-46df-419a-9c67-4a69d1be66ae/roles \
  -H 'authorization: Bearer <token received from previous call> \
  -H 'cache-control: no-cache' \
  -H 'postman-token: 248fef6b-9c24-3aa3-91ae-a6f11e01e55c'

响应是:

{
   "error": "unknown_error"
}

Using Postman and three conditions should support it. #1 "test-user" needs a "view-clients" role. It comes from "realm-management" client. enter image description here

#2 Using "admin-cli" client and Change Access Type with "confidential" and turn on "Authorization Enabled" is "ON" enter image description here

#3 using "admin-cli"'s secret for Postman token call. enter image description here

#4 使用 #3 的秘密和 #1 用户的凭据(用户名和密码)获取令牌

  • the token "expires_in" is very short, you need to makes a longer by UI. it is admin-cli's advanced settings(for just testing purpose) enter image description here enter image description here

#5 你需要保存一个用于调用客户端/角色API的令牌

  • it is same #4's API on Tests Tab of Postman. enter image description here

#6 Call list client/role API with #5's token. enter image description here

#7 find "custom-client" id from #6 enter image description here

#8 call custom role API using #7 id. enter image description here it should be match with UI's roles. enter image description here

祝你好运!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从keycloak中的自定义客户端获取角色? 的相关文章

随机推荐

  • 如何在 Ubuntu 11.10 上安装 Django?

    我在用着在 ubuntu 上安装 Django 的权威指南 http felecan com 2011 definitive guide installing django ubuntu 具有讽刺意味的是 我需要更明确的东西 因为我无法让它
  • 使用CSS停止div调整父div的大小

    http jsfiddle net ETkkR http jsfiddle net ETkkR div div class post img src http dummyimage com 180x120 000 fff alt Image
  • 关闭别人的代码审查 TFS 2015

    我负责的开发团队人员流动率很高 我有 100 个处于 已请求 状态的代码审查 因为开发人员在离开公司之前没有关闭它们 我通过右键单击并分配给自己在 TFS 中获得了这些所有权 但它并没有给我关闭的选项 根据这个链接 https social
  • 在 IE 中使用 JavaScript 中的 XMLSerializer 时,SVG 标记上出现不需要的命名空间

    我正在尝试使用 JavaScript DOM APIXML序列化器 https developer mozilla org en US docs XMLSerializer将 SVG 元素转换为其代表性标记 这是用于创建元素并将其序列化的基
  • 为什么 C 中的复合文字可以修改

    人们通常会将 不可修改 与术语 字面量 联系起来 char str Hello World str B Bus Error 然而 当使用复合文字时 我很快发现它们是完全可修改的 查看生成的机器代码 您会看到它们被推入堆栈 char str
  • MySQL 跳过名称解析

    我在 1 台专用服务器中使用 MariaDB MySQL 所有数据库和 PHP 都在本地服务器中 我不使用远程服务器 运行 mysqltuner 时 我收到使用 跳过名称解析 所以我在 my cnf 中添加了这段代码 skip name r
  • jetty如何处理多个请求

    我已经使用 jetty tomcat 应用服务器处理 Spring Web 应用程序大约两年了 但是我仍然困惑的是这些服务器中如何处理多个请求 我知道 spring 对于创建单例很有帮助 但我的理解仅限于此 有人可以指出任何可以帮助我了解如
  • ruby 中是否可以取消定义变量?

    在 ruby 中 有没有办法在定义变量或常量后 取消定义 变量或常量 在我们的 Rails 环境中 我们将三个内容之一定义为true 取决于环境 TESTING DEVELOPMENT or PRODUCTION 然后 在控制器代码中 我们
  • 在Fabric js中的两个对象之间添加动画

    我有一个非常基本的应用程序 可让您创建形状并用线连接它们 为此 您需要执行以下操作 Example 1 Click new animation 2 add rectangle 3 add child 4 add circle 您可以移动形状
  • 将基本脚本转换为 Objective C(货币格式)

    我有这个基本的类似脚本 我需要将其转换为 Objective C 它将大单位的金钱转换为缩短的版本 即 1 2m 等 我已经完成了大部分转换 但最大的问题是我我就在最后 原来的基本代码是 Basic Code Function ShortC
  • mysqli_result 类的对象无法转换为字符串返回 mysql 平均值 [重复]

    这个问题在这里已经有答案了 有人能解释一下我如何输出下面的sql结果吗 当前收到 mysqli result 类的对象无法转换为字符串 sql SELECT AVG ab satisfactionScore AS AverageSatisf
  • Jenkins 管道作业:从字符串参数设置睡眠时间?

    我是 Jenkins Pipeline 工作的新手 我面临着一个无法解决的问题 我有一个带有硬编码的舞台sleep秒值 stage wait prior starting smoke testing echo Waiting 5 minut
  • 抑制 C 宏变量替换

    我有这段代码 实际上是垃圾收集 Forth 系统解释器的一部分 define PRIMITIVE name do VocabEntry entry VocabEntry gc alloc sizeof VocabEntry entry gt
  • 如何让 Capistrano 3 使用 RVM ruby​​?

    Gemfile gem capistrano gt 3 0 0 gem capistrano rails gem capistrano bundler gem capistrano rvm gem capistrano3 puma 部署 r
  • AspNetCore 2.1 中使用 WsFederation 时出现注销 (LogOut) 错误

    我在 ASP NET Core 2 1 应用程序中注销 注销 时收到以下错误 没有为 联合 方案注册注销身份验证处理程序 注册的注销方案有 WsFederation Cookies 您是否忘记调用 AddAuthentication Add
  • 撇号打印为 â\x80\x99

    import requests from bs4 import BeautifulSoup import re source url requests get http www nytimes com pages business inde
  • PostgreSQL:在 Ubuntu 上重置 PostgreSQL 的密码 [关闭]

    Closed 这个问题是无关 help closed questions 目前不接受答案 在 Ubuntu 中 我安装了 PostgreSQL 数据库并为服务器创建了一个超级用户 如果我忘记了 postgresql 超级用户的密码 如何为该
  • vue-router - 使用新导航取消从“/”到“/password”的导航

    尝试导航到密码页面 vue router 抛出此错误 Uncaught in promise Error Navigation cancelled from to password with a new navigation 导航到密码页面
  • python 多处理/线程清理

    我有一个 python 工具 基本上有这样的设置 main process P1 gt spawns a process P2 that starts a tcp connection gt spawns a thread T1 that
  • 如何从keycloak中的自定义客户端获取角色?

    为了获得自定义客户端中的角色 我知道我需要执行两个 API 一种是获取访问令牌 一种是获取角色 我的疑问是 我应该通过在标头中发送 admin CLI 详细信息来获取 accessToken 还是因为我想要我创建的自定义客户端的角色 因为