Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Alex Bilbie的OAuth2服务器PHP验证API调用是正确的资源请求?_Php_Oauth_Oauth 2.0_Oauth2 Server - Fatal编程技术网

如何使用Alex Bilbie的OAuth2服务器PHP验证API调用是正确的资源请求?

如何使用Alex Bilbie的OAuth2服务器PHP验证API调用是正确的资源请求?,php,oauth,oauth-2.0,oauth2-server,Php,Oauth,Oauth 2.0,Oauth2 Server,我在我的应用程序上使用Alex Bilbie的OAuth2服务器php for OAuth。我想用它来保护我的API。我已经把授权请求、授权码、访问令牌都整理好了,它运行得很好 但是如何为API实现这一点呢 有一个主控制器提供了一般的方法:simple gets等。在该构造函数中,我想确保他们调用的URL是有效的。如果存在access_令牌,则将关联的客户端绑定到关联的用户 然后,在控制整个/products资源的控制器中,我要验证此调用的作用域,即检查访问令牌是否具有products\u wr

我在我的应用程序上使用Alex Bilbie的OAuth2服务器php for OAuth。我想用它来保护我的API。我已经把授权请求、授权码、访问令牌都整理好了,它运行得很好

但是如何为API实现这一点呢

有一个主控制器提供了一般的方法:simple gets等。在该构造函数中,我想确保他们调用的URL是有效的。如果存在access_令牌,则将关联的客户端绑定到关联的用户

然后,在控制整个/products资源的控制器中,我要验证此调用的作用域,即检查访问令牌是否具有products\u write作用域的post/put/patch

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

$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)""
    }
}