通过cURL获取访问令牌

时间:2018-05-09 14:57:17

标签: curl keycloak

简单问题:

为什么以下代码有效...(它返回访问令牌就好了)

curl --data "grant_type=client_credentials&client_id=synchronization_tool&client_secret=8f6a6e73-66ca-4f8f-1234-ab909147f1cf" http://localhost:8080/auth/realms/master/protocol/openid-connect/token 

而且这个没有?

curl -d  '{"grant_type":"client_credentials","client_secret":"8f6a6e73-66ca-4f8f-1234-ab909147f1cf","client_id":"synchronization_tool"}' http://localhost:8080/auth/realms/master/protocol/openid-connect/token -H "Content-Type: application/json"

它给了我:

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

Aren他们应该是两个完全类似的请求吗?

2 个答案:

答案 0 :(得分:1)

好吧,似乎那些cURL查询不是模拟的。

此外,端点http://localhost:8080/auth/realms/master/protocol/openid-connect/token不理解JSON,它只接受x-www-form-urlencoded问题。

答案 1 :(得分:1)

curl -d 'client_id=xxx' -d 'username=xxx' -d 'password=xxx' -d 'grant_type=password' 'http://localhost:8080/auth/realms/YOUR_REALM_NAME/protocol/openid-connect/token' | python -m json.tool

这对我有用,它将为您提供access_tokensession_token

相关问题