oauth-2.0keycloakopenid-connect

How to create keyclock clientSecret via API


I’m using keycloak version 20.0.2, and I want to know if it possible to create clientSecret through a post request (/admin/realms/:realm/clients/:id/client-secret).

I want to send body to post request with my own generated client secret value

https://{host}/admin/realms/{realm}/clients/{id}/client-secret

Body: {  
   "clientSecret":"my own generated value here"  
}

Response: {  
  type: "secret",  
  value: "my own generated value here" 
}

Solution

  • You have two options.

    #1 One is create new client API with own secret

    #2 Second is can random generated secret on existing client by Keycloak

    But no option update the client secrete with your own.

    #1 One is create new client API with own secret

    POST {Keycloak URL}/admin/realms/test/clients
    

    Body

    {
        "clientId": <new client ID>,
        "name": <Cleint Name>,
        "enabled": true,
        "clientAuthenticatorType": "client-secret",
        "secret": <my-own-secret>
    }
    

    Example by Postman enter image description here

    In Body

    {
        "clientId": "Test-Client",
        "name": "Test-Client-New",
        "enabled": true,
        "clientAuthenticatorType": "client-secret",
        "secret": "my-new-own-secret"
    }
    

    Result enter image description here enter image description here

    #2 Second is can random generated secret by Keycloak

    POST {Keycloak URL}/admin/realms/{my-realm}/clients/{client-uuid}/client-secret
    

    Input Body

    None
    

    Response Body

    {
        "type": "secret",
        "value": <Random created new secret by Keycloak>
    }
    

    enter image description here enter image description here

    Result in Keycloak UI enter image description here