FOSOAuthServerBundle:无效的grant_type参数或缺少参数 [英] FOSOAuthServerBundle: Invalid grant_type parameter or parameter missing
问题描述
我正在尝试使用Symfony 3.1和FOSRestBundle,FOSUserBundle和FOSOAuthServerBundle构建REST API.我已按照 https://gist.github.com/tjamps/11d617a4b318d65ca583 a>.
I'm trying to build a REST API using Symfony 3.1 and the FOSRestBundle, FOSUserBundle and FOSOAuthServerBundle. I managed to achieve this following the guide at https://gist.github.com/tjamps/11d617a4b318d65ca583.
我现在正在努力进行身份验证过程.当我使用请求正文中json编码的参数向服务器发出POST请求以进行身份验证(到localhost:8000/oauth/v2/token)时:
I'm now struggling at the authentication process. When I make a POST request to the server for authentication (to localhost:8000/oauth/v2/token) with the parameters encoded in json in the request body:
{
"grant_type": "password",
"client_id": "1_myveryverysecretkey",
"client_secret": "myveryverymostsecretkey",
"username": "theuser",
"password": "thepassword"
}
其他HTTP标头如下:
The additional HTTP Headers are the following:
Accept: application/json
Cache-Control: no-store, private
Connection: close
Content-Type: */json
根据指南的建议,数据库表oauth2_client中的客户端具有密码" grant_type a:1:{i:0;s:8:"password";}
.
The client in the db table oauth2_client has the "password" grant_type a:1:{i:0;s:8:"password";}
, as suggested by the guide.
服务器正在接受请求,但我总是得到响应
The server is accepting the request, but I always get the response
{"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}
有什么建议我想念的吗?谢谢!
Any suggestions what I am missing? Thanks!
推荐答案
确实是FOSRestBundle 身体监听器是此问题的主要原因".
really the FOSRestBundle Body Listener is the main 'cause' of this issue.
数组标准化器配置
fos_rest:
body_listener:
array_normalizer: fos_rest.normalizer.camel_keys
它将_
转换为驼峰式格式.
it converts _
to camel case format.
该解决方案目前已将其从我的配置中删除.
The solution was remove it of my configuration by the moment.
再次调用/oauth/v2/token
端点:
{
"access_token": "NDBlZGViN2YwZGM5MTQ3ZTgwN2FhOGY4MDU4MTc1MTY2YzZmOThlMTdkM2JiZDJmMDVmNTg3MjU4N2JmODY3ZA",
"expires_in": 3600,
"token_type": "bearer",
"scope": null,
"refresh_token": "MDRiODllNjlhZWYxZjI5MjlhMzAxNGVhMDY5NjQxMmVmNDE5MzY3YzU0MGM0MDU1ZTVlY2Y2Zjg4ZTYyYzU3Mw"
}
这篇关于FOSOAuthServerBundle:无效的grant_type参数或缺少参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!