如何通过keypolt API获取客户端机密?

2024-10-05 14:32:17 发布

您现在位置:Python中文网/ 问答频道 /正文

如何通过keypolt 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错误。

我做错什么了?


Tags: 文档clientapiid客户端datagetsecret
2条回答

我想你的身份验证没用。

  1. 你需要一个代币。可以使用OpenID生成(请参见docs)。
  2. 使用令牌(通过头授权),您可以请求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"})

{id}在URL中不是clientId,它不同于clientId。 它是keycolpt惟一id(即uuid),类似于628e4b46-3d79-454f-9b1c-e07e86ee7615

GET /admin/realms/{realm}/clients/{id}/client-secret

您可以使用此api获取id,它返回ClientRepresentation列表,该列表同时具有idclientId,使用id

GET /{realm}/clients

`

相关问题 更多 >