Keycloak: Missing parameter: code, How to obtain the code in Keycloak using the POST request

Viewed 3211

I am trying to make a POST request using the POSTMAN to my Keycloak but I keep getting the error Code not valid. I am not sure how to get CODE for the keycloak.

I have created the Realm, User, Client etc. when I make the request using the foolowing parameter then I get the success message with access token:

POST http://localhost:8080/auth/realms/blog_demo/protocol/openid-connect/token

grant_type: password
redirect_url: http://localhost:3000/callback
client_id: blog-post-demo-client-001
client_secret: 9a465bd2-1076-4c18-a12a-b53zd4f0908q
response_type: code
username: user1
password: password123

I put the access token in the https://jwt.io/ to obtain some more info but I don't see the code anywhere.

Now I am trying to make the request using the following information:

 POST http://localhost:8080/auth/realms/blog_demo/protocol/openid-connect/token
    
    grant_type: authorization_code
    redirect_url: http://localhost:3000/callback
    client_id: blog-post-demo-client-001
    client_secret: 9a465bd2-1076-4c18-a12a-b53zd4f0908q
    response_type: code

I get the following error:

{
    "error": "invalid_request",
    "error_description": "Missing parameter: code"
}

I know I have to send the code in my request but I am not sure what value should I send for it. Can someone please help me with this.

enter image description here

1 Answers

Remove unnecessary parameters from your request. This should work :

POST http://localhost:8080/auth/realms/blog_demo/protocol/openid-connect/token

grant_type: password
client_id: blog-post-demo-client-001
client_secret: 9a465bd2-1076-4c18-a12a-b53zd4f0908q
username: user1
password: password123
Related