我是Zend Framework 2的新手。我试图获得与邮差(chrome扩展)工作的登录访问场景。我已经通过论坛,但我不确定如果我错过了什么或没有。以下是我到目前为止所采取的步骤:在MYSQL中,我已经相应地设置了表,并且在oauth_clients
表中有以下字段的用户:
-
client_id
:testclient
-
client_secret
:testpass
-
redirect_uri
:/oauth/receivecode
(我不确定 -
grant_type
:password
(我想使用该服务进行身份验证和访问网站或登录访问场景的授权)
其余字段为NULL
。其他表中没有其他条目。我在Postman中这样设置参数:
-
Authorization
:Oauth2
标题:
-
Accept
:application/json
Content-Type
: application/json
原始正文如下:
{
"client_id":"testclient",
"client_secret":"testpass",
"grant_type":"password"
}
我将请求发布到:www.dummy.dev/oauth/authorize
当我发布请求时,我得到的是:
{
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "invalid_request",
"status": 302,
"detail": "Invalid or missing response type"
}
为什么我得到这个错误信息?
此错误在OAuth2 AuthorizeController
中触发。
控制器检查$response_type
是否有效。如果不是,则返回此错误消息。
在第313行你看到:
protected function getValidResponseTypes()
{
return array(
self::RESPONSE_TYPE_ACCESS_TOKEN,
self::RESPONSE_TYPE_AUTHORIZATION_CODE,
);
}
这些常量在AuthorizeControllerInterface
中定义:
const RESPONSE_TYPE_AUTHORIZATION_CODE = 'code';
const RESPONSE_TYPE_ACCESS_TOKEN = 'token';
所以在处理请求的过程中,这个$response_type
值没有正确设置。为了正确验证请求,应该将其设置为token
或code
。
redirect uri是不必要的,也可以在数据库中为空。POST的正确uri是www.dummy.dev/oauth
, Postman的原始参数是:
{
"client_id":"dev.dummy",
"username":"testclient",
"password":"testpass",
"grant_type":"password"
}
password的值在数据库中存储并编码(使用bcrypt)。client_id
和client_secret
在这种情况下并不重要,因为我自己的网站是我的API的客户端。