【问题标题】:How to verify that API call is proper resource request with Alex Bilbie's OAuth2 Server PHP?如何使用 Alex Bilbie 的 OAuth2 服务器 PHP 验证 API 调用是正确的资源请求?
【发布时间】:2015-04-28 17:05:28
【问题描述】:

我在我的应用程序上使用 Alex Bilbie 的 OAuth2-server-php 进行 OAuth。我想用它来保护我的 API。我已经把授权请求、授权码、访问令牌都整理好了,效果很好。

但是如何为 API 实现这个呢?

有一个主控制器提供通用方法:简单获取等。在那个构造函数中,我想确保他们调用的 URL 是有效的。如果access_token存在,将关联的客户端绑定到关联的用户。

然后,在控制整个/products 资源的控制器中,我想验证此调用的范围,即检查access_token 是否具有products_write 范围。

回到主控制器,在构造函数中是这样的:

$oauth = new Oauth(); //creates a new instance of the OAuth server, with all relevant info regarding db, grant types, and supported scopes.
if(!$oauth->server->verifyResourceRequest($oauth->request, $oauth->response)) {
  echo '<pre>';
  var_dump($oauth->server->getResponse());
  exit();
}

它引起了大惊小怪:

object(OAuth2\Response)#129 (5) {
    ["version"]=>
    string(3) "1.1"
    ["statusCode":protected]=>
    int(400)
    ["statusText":protected]=>
    string(11) "Bad Request"
    ["parameters":protected]=>
    array(2) {
            ["error"]=>
            string(15) "invalid_request"
            ["error_description"]=>
            string(80) "Only one method may be used to authenticate at a time (Auth header, GET or POST)"
    }
    ["httpHeaders":protected]=>
    array(2) {
            ["Cache-Control"]=>
            string(8) "no-store"
            ["WWW-Authenticate"]=>
            string(149) "Bearer realm="Service", error="invalid_request", error_description="Only one method may be used to authenticate at a time (Auth header, GET or POST)""
    }
}

这里有什么问题,我错过了什么?教程或文档中没有关于实际验证资源请求的内容。

【问题讨论】:

    标签: php oauth oauth-2.0 oauth2-server


    【解决方案1】:

    问题是我已经登录到主网站。它看到我已经通过它进行了身份验证,这是不允许的。

    【讨论】:

      猜你喜欢
      • 2017-06-23
      • 2022-08-21
      • 2017-01-12
      • 2017-04-13
      • 2016-01-18
      • 2023-02-22
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多