Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access the keycloak API from postman

Tags:

I have tried to access the keycloak API from the postman. but it is showing 400 bad request.

I was calling api in the below format.

http://{hostname}:8080/auth/realms/master/protocol/openid-connect/token?username=admin&password=admin&client_id=admin-cli&grant_type=password

In the headers I have set the content_type as application/x-www-form-urlencoded

I am getting the response as below.

{
    "error": "invalid_request",
    "error_description": "Missing form parameter: grant_type"
}

Can any one help me.Any help will be appreciated. thanks in advance

like image 834
Programmer Avatar asked Mar 16 '18 05:03

Programmer


People also ask

How do you use a postman with a Keycloak?

Navigate to the Postman Authorization tab of your request. From the Type dropdown menu, select OAuth 2.0: Click on the Get New Access Token button that will open a dialog box for configuring the identity server (Keycloak in our case).


2 Answers

A bit late for this question, but you did ask about postman and not curl. So you have to put the options in x-www-form-urlencoded enter image description here

like image 67
UchihaItachi-Inactive-Account Avatar answered Oct 19 '22 22:10

UchihaItachi-Inactive-Account


You call API through POST client

URL - http://localhost:8080/auth/realms/Demo/protocol/openid-connect/token

So here in above url i am using Demo as my realm instead of master.

ContentType - "Content-Type":"application/x-www-form-urlencoded"

Params:

{
"client_secret" : "90ec9638-7647-4e65-ad20-b82df3341084",
"username" : "ankur",
"password" : "123456",
"grant_type" : "password",
"client_id": "app-client"
}

Set Header as below

enter image description here

Data Need to be passed as shown below enter image description here

like image 26
Ankur Singhal Avatar answered Oct 19 '22 23:10

Ankur Singhal