Luracast Restler多个身份验证类不允许访问


Luracast Restler Multiple Authentication Classes Not Allowing Access

我定义了两个身份验证类。

  1. API密钥(APIKeyAuth)
  2. 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(在我看来,它不应该像rest方法那样已装饰为使用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密钥并添加逻辑?(似乎是错误的做法)。

Restler up to RC5串行处理身份验证类,这意味着所有身份验证类都必须返回true才能通过受保护的api调用

由于RC6,这已更改为并行,这意味着任何一个身份验证类都可以允许访问受保护的api