如何通过 Keycloak API 获取客户端密码? [英] How to get client secret via Keycloak API?
本文介绍了如何通过 Keycloak API 获取客户端密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过 Keycloak API 获取客户端密钥?
How to get client secret via Keycloak API?
在文档中我看到:
GET/admin/realms/{realm}/clients/{id}/client-secret
我的代码如下:
data = {
"grant_type" : 'password',
"client_id" : 'myclientid',
"username" : 'myusername',
"password" : 'mypassword'
}
response = requests.get("https://mylink.com/auth/admin/realms/{myrealm}/clients/{myclientid}/client-secret", data=data, headers= {"Content-Type": "application/json"})
我总是收到 401 错误.
I always get 401 error.
我做错了什么?
推荐答案
我认为您的身份验证不起作用.
I think your authentication it's not working.
- 您需要一个令牌.您可以使用 OpenID 生成(请参阅 docs).
- 使用令牌(通过标头授权),您可以向 API 发出请求.
示例:
获取令牌
data = {"username": "username", "password": "password",
"client_id": "client_id", "client_secret": "client_secret",
"grant_type": "password"}
token = request.post("https://{server-url}/"realms/{realm-name}/protocol/openid-connect/token", data=data)
请求 API
response = requests.get("https://mylink.com/auth/admin/realms/{myrealm}/clients/{myclientid}/client-secret", data=data, headers= {"Authorization": "Bearer " + token.get('access_token'), "Content-Type": "application/json"})
这篇关于如何通过 Keycloak API 获取客户端密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文