java 从 postman 访问 keycloak API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49313554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access the keycloak API from postman
提问by Programmer
I have tried to access the keycloak API from the postman. but it is showing 400 bad request.
我试图从邮递员那里访问 keycloak API。但它显示 400 个错误的请求。
I was calling api in the below format.
我正在以以下格式调用 api。
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
在标题中,我设置了 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
任何人都可以帮助我。任何帮助将不胜感激。提前致谢
回答by UchihaItachi
回答by Ankur Singhal
You call API through POST client
您通过 POST 客户端调用 API
URL- http://localhost:8080/auth/realms/Demo/protocol/openid-connect/token
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
.
因此,在上面的 url 中,我将其Demo
用作我的领域而不是master
.
ContentType- "Content-Type":"application/x-www-form-urlencoded"
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
设置标题如下
回答by Pablo Bastidas
The URL you are using is to obtain the token.
您使用的 URL 用于获取令牌。
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
令牌请求应该是 POST 调用,您发布的请求是 GET 请求。下面是一个关于如何请求的 CURL 示例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'
回答by Rajat jain
You can also use CURL to get information
也可以使用 CURL 来获取信息
curl -L -X POST 'http://<serveraddress>/auth/realms/<realmname>/protocol/openid-connect/token' -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'client_id=<clientid>' --data-urlencode 'grant_type=password' --data-urlencode 'client_secret=<clientsecret>' --data-urlencode 'scope=openid' --data-urlencode 'username=<username>' --data-urlencode 'password=<password>'