我正在尝试使用Symfony 3.1和FOSRestBundle,FOSUserBundle和FOSOAuthServerBundle构建REST API.我已按照 gist.github/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 gist.github/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
发布评论