【发布时间】:2015-05-22 00:47:32
【问题描述】:
我定义了两个身份验证类。
- API 密钥 (APIKeyAuth)
- OAUTH2(OAUTH2 服务器)
在我的 index.php 中,我定义了以下内容
$r = new Restler();
$r->addAuthenticationClass('APIKeyAuth');
$r->addAuthenticationClass('OAUTH2Server');
然后我保护 APIKeyAuth 的其余方法之一
/**
* @access protected
* @class APIKeyAuth{@requires apikey}
*/
public function .......etc
如果我调试它,它会通过第一步,$authObj(请参阅下面来自 restler.php 的代码)将 是 APIKeyAuth。它检查 __isAllowed 并返回 true ... 这很好。
然后它会通过 OAUTH2Server(在我看来,它不应该像其他方法一样) 被修饰为使用 APIKeyAuth。
因此它通过并且 OAUTH2Server 中的 __isAllowed 为 false,因此用户将获得 Unauthorzied 响应。
foreach ($this->authClasses as $authClass) {
$authObj = Scope::get($authClass);
if (!method_exists($authObj,
Defaults::$authenticationMethod)
) {
throw new RestException (
500, 'Authentication Class ' .
'should implement iAuthenticate');
} elseif (
!$authObj->{Defaults::$authenticationMethod}()
) {
throw new RestException(401);
}
}
我是否需要更改 OAUTH2 服务器以检查其是否使用 API 密钥并添加逻辑? (似乎是错误的做法)。
【问题讨论】:
标签: php restful-authentication restler