【发布时间】:2014-06-22 15:42:34
【问题描述】:
我正在尝试使用 apigility 对我的其余 API 进行一些单元测试,并使用 OAuth2 进行保护 (zfcampus/zf-oauth2)。身份验证和接收访问令牌完美运行
$this->dispatch('/api/oauth', HttpRequest::METHOD_POST, array(
'username' => 'username',
'password' => 'password',
'client_id' => 'web-app',
'grant_type' => 'password'
), true);
/** @var $response \Zend\Http\PhpEnvironment\Response */
$response = $this->getResponse();
$phpNative = \Zend\Json\Json::decode($response->getContent(), \Zend\Json\Json::TYPE_OBJECT);
echo "\n".$phpNative->access_token."\n";
$this->assertResponseStatusCode(200);
但是,我尝试发送访问令牌并访问受限资源,但我得到“拒绝访问”。发送“访问令牌”的正确方法是什么
【问题讨论】:
-
您需要将访问令牌滚动到标头中..特别是
authorization : Bearer afdkj23423l4kh23bjf3nf请参阅:bshaffer.github.io/oauth2-server-php-docs/grant-types/…
标签: php unit-testing rest zend-framework2 oauth-2.0