我正在尝试使用 Symfony 3.1 和 FOSRestBundle、FOSUserBundle 和 FOSOAuthServerBundle 构建 REST API。我按照https://gist.github.com/tjamps/11d617a4b318d65ca583上的指南设法实现了这一点。
我现在在身份验证过程中苦苦挣扎。当我使用请求正文中以 json 编码的参数向服务器发出 POST 请求以进行身份验证(到 localhost:8000/oauth/v2/token)时:
{
"grant_type": "password",
"client_id": "1_myveryverysecretkey",
"client_secret": "myveryverymostsecretkey",
"username": "theuser",
"password": "thepassword"
}
附加的 HTTP 标头如下:
Accept: application/json
Cache-Control: no-store, private
Connection: close
Content-Type: */json
正如指南所建议的,数据库表 oauth2_client 中的客户端具有“密码” grant_type a:1:{i:0;s:8:"password";}
。
服务器正在接受请求,但我总是得到响应
{"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}
有什么建议我缺少什么吗?谢谢!