我的本地机器上有独立的钥匙斗篷。
我创建了名为“spring-test”的新领域,然后创建了名为“登录-app”的新客户端。
根据其余文件:
POST: http://localhost:8080/auth/realms/spring-test/protocol/openid-connect/token
{
"client_id": "login-app",
"username": "user123",
"password": "pass123",
"grant_type": "password"
}应该给我jwt令牌,但是我收到了错误的响应请求。
{
"error": "invalid_request",
"error_description": "Missing form parameter: grant_type"
}我假设我的配置中缺少了一些东西。
编辑:我使用的是json,但是应该是application/x-www-form-urlencoded:下面的主体工作:
token_type_hint:access_token&token:{token}&client_id:{client_id}&client_secret:{client_secret}发布于 2018-12-15 16:48:33
您应该在POST请求中发送数据,其中Content-Type标头值设置为application/x-www-form-urlencoded,而不是json。
发布于 2020-04-01 14:00:28
卷曲
curl -X POST \
http://localhost:8080/auth/realms/api-gateway/protocol/openid-connect/token \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 73' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Cookie: JSESSIONID=F8CD240FF046572F864DC37148E51128.a139df207ece; JSESSIONID=65D31B82F8C5FCAA5B1577DA03B4647C' \
-H 'Host: localhost:8080' \
-H 'Postman-Token: debc4f90-f555-4769-b392-c1130726a027,d5087d9f-9253-48bd-bb71-fda1d4558e4d' \
-H 'User-Agent: PostmanRuntime/7.15.2' \
-H 'cache-control: no-cache' \
-d 'grant_type=password&client_id=api-gateway&username=admin&password=temp123'邮递员(为参数选择x-www-form-urlencoded选项)

发布于 2019-07-07 20:35:46
对于那些从寻找JavaScript解决方案的搜索中来到这里的人来说。
下面是使用code将access_token与keycloak授权进行交换时的一个示例。
发送请求:
const params = new URLSearchParams({
grant_type: 'authorization_code',
client_id: 'client-id-here',
code: 'code-from-previous-redirect',
redirect_uri: location.protocol + '//' + location.host
});
axios({
method: 'post',
url: 'https://my-keycloak.authority/token',
data: params.toString(),
config: {
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}
}).then(response => {
console.log(response.data);
}).catch(error => {
console.error(error);
});您需要发送带有参数的POST请求,将其作为请求正文中的URL编码字符串。 FormData对象不工作。
https://stackoverflow.com/questions/53795179
复制相似问题