Access the keycloak API from postman

社会主义新天地 提交于 2019-11-30 23:04:02

问题


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


回答1:


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




回答2:


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

Data Need to be passed as shown below




回答3:


The URL you are using is to obtain the token.

The token request should be a POST call, the request you post is a GET request. Below a CURL example about how to request the access_token

curl -X POST \
   http://{hostname}:8080/auth/realms/{realm}/protocol/openid-connect/token \
   -H 'Content-Type: application/x-www-form-urlencoded' \
   -d 'username=admin&password=admin&grant_type=password&client_id=admin-cli'


来源:https://stackoverflow.com/questions/49313554/access-the-keycloak-api-from-postman

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!