为什么在 apiagility 中使用 Postman 和 oauth2 进行登录访问时会出现错误?
Why am I getting error when I use Postman and oauth2 for login access case in apiagility?
我是 Zend Framework 2 的新手。我正在尝试让登录访问场景与 Postman(chrome 扩展)一起使用。我浏览了论坛,但我不确定我是否遗漏了什么。所以这是我到目前为止采取的步骤:
在 MYSQL 中,我相应地设置了 tables 并且 oauth_clients
table 中有一个用户具有以下字段:
client_id
: testclient
client_secret
: testpass
redirect_uri
: /oauth/receivecode
(我不确定
有人可以解释一下吗?)
grant_type
: password
( 我想使用该服务进行身份验证
和访问网站或登录访问场景的授权)
其余字段为NULL
。其他 table 中没有其他条目。
我在 Postman 中这样设置参数:
Authorization
: Oauth2
Headers:
Accept
: application/json
Content-Type
: application/json
原始 body 就像:
{
"client_id":"testclient",
"client_secret":"testpass",
"grant_type":"password"
}
我post请求:
www.dummy.dev/oauth/authorize
当我 post 请求时,这是我得到的:
{
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "invalid_request",
"status": 302,
"detail": "Invalid or missing response type"
}
为什么我会收到此错误消息?
触发此错误here in the OAuth2 AuthorizeController
。
控制器检查$response_type
是否有效。如果不是它 returns 这个错误信息。
在 line 313 你看到:
protected function getValidResponseTypes()
{
return array(
self::RESPONSE_TYPE_ACCESS_TOKEN,
self::RESPONSE_TYPE_AUTHORIZATION_CODE,
);
}
这些常量定义为in the 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"
}
密码值在数据库中存储和编码(使用 bcrypt)。 client_id
和 client_secret
在这种情况下并不重要,因为我自己的网站是我的 API.
的客户端
我是 Zend Framework 2 的新手。我正在尝试让登录访问场景与 Postman(chrome 扩展)一起使用。我浏览了论坛,但我不确定我是否遗漏了什么。所以这是我到目前为止采取的步骤:
在 MYSQL 中,我相应地设置了 tables 并且 oauth_clients
table 中有一个用户具有以下字段:
client_id
:testclient
client_secret
:testpass
redirect_uri
:/oauth/receivecode
(我不确定 有人可以解释一下吗?)grant_type
:password
( 我想使用该服务进行身份验证 和访问网站或登录访问场景的授权)
其余字段为NULL
。其他 table 中没有其他条目。
我在 Postman 中这样设置参数:
Authorization
:Oauth2
Headers:
Accept
:application/json
Content-Type
:application/json
原始 body 就像:
{
"client_id":"testclient",
"client_secret":"testpass",
"grant_type":"password"
}
我post请求:
www.dummy.dev/oauth/authorize
当我 post 请求时,这是我得到的:
{
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "invalid_request",
"status": 302,
"detail": "Invalid or missing response type"
}
为什么我会收到此错误消息?
触发此错误here in the OAuth2 AuthorizeController
。
控制器检查$response_type
是否有效。如果不是它 returns 这个错误信息。
在 line 313 你看到:
protected function getValidResponseTypes()
{
return array(
self::RESPONSE_TYPE_ACCESS_TOKEN,
self::RESPONSE_TYPE_AUTHORIZATION_CODE,
);
}
这些常量定义为in the 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"
}
密码值在数据库中存储和编码(使用 bcrypt)。 client_id
和 client_secret
在这种情况下并不重要,因为我自己的网站是我的 API.