Mark
Mark

Reputation: 83

How to get client secret from Keycloak using curl?

I have setup Keycloak with a Client, that has Access Type confidential and generated a client secret. Now I need to get the client secret via commandline. How can i accomplish that?

Keycloak is running inside a docker container. I've tried to adapt a similar question, which targets using python, but I even fail getting a token first.

Upvotes: 8

Views: 11421

Answers (1)

ravthiru
ravthiru

Reputation: 9633

You need get Access Token using below curl command for realm myrealm

curl http://localhost:8080/auth/realms/myrealm/protocol/openid-connect/token -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=password&username=testuser&password=test123&client_id=admin-cli'

hold access_token from above output.

Get the Clients and their ids using

curl   http://localhost:8080/auth/admin/realms/myrealm/clients -H 'Content-Type: application/json' -H  'Authorization: Bearer <<ACCESS_TOKEN>>'

Get id from the output, will some thing like this "id":"e65ba232-08ff-4f9b-84a6-bd6147340dfd"

Then get the client secret using below command

curl  http://localhost:8080/auth/admin/realms/myclient/clients/e65ba232-08ff-4f9b-84a6-bd6147340dfd/client-secret -H 'Content-Type: application/json' -H  'Authorization: Bearer <<ACCESS_TOKEN>>'

output will be something like this

{"type":"secret","value":"9a16ceb5-1f26-4812-ae4d-9e8336efef91"}

Upvotes: 16

Related Questions