php - 使用 PUT http 动词时通过查询参数传递 Oauth2 token ?

标签 php api oauth-2.0 laravel http-verbs

我正在使用 league\oauth2-server并在我使用 GET http 动词时让它完美地工作。

然而,当执行 PUT 请求时,我遇到了问题

Call to undefined method League\OAuth2\Server\Util\Request::PUT()

抛出这个错误的具体代码是一个函数Server/Resource.php file

$accessToken = $this->getRequest()->{$method}($this->tokenKey);

来自函数

protected function determineAccessToken($headersOnly = false)
{
    if ($header = $this->getRequest()->header('Authorization')) {
        // Check for special case, because cURL sometimes does an
        // internal second request and doubles the authorization header,
        // which always resulted in an error.
        //
        // 1st request: Authorization: Bearer XXX
        // 2nd request: Authorization: Bearer XXX, Bearer XXX
        if (strpos($header, ',') !== false) {
            $headerPart = explode(',', $header);
            $accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $headerPart[0]));
        } else {
            $accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header));
        }
        $accessToken = ($accessToken === 'Bearer') ? '' : $accessToken;
    } elseif ($headersOnly === false) {
        $method = $this->getRequest()->server('REQUEST_METHOD');
        $accessToken = $this->getRequest()->{$method}($this->tokenKey);
    }

    if (empty($accessToken)) {
        throw new Exception\InvalidAccessTokenException('Access token is missing');
    }

    return $accessToken;
}

我正在使用 POSTMAN 请求客户端来测试请求 Postman Request

最佳答案

它抛出该错误是因为不允许对 Web 服务的 PUT 请求。这是有道理的,因为您真的永远不需要为 OAuth2 请求执行 PUT 请求。 PUT 告诉另一端的 RESTful 服务您正在尝试更新特定实体。 OAuth2 没有要更新的实体,只能检索。

也许更好地理解您正在尝试做什么可以解释您为什么使用 PUT,但对于 OAuth2,它应该始终是 GET 请求。

关于php - 使用 PUT http 动词时通过查询参数传递 Oauth2 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18908403/

相关文章:

php - ElasticSearch Laravel侦察异常(exception)

php - 通过PHP从Json获取 channel 主页URL

python - 如何通过 python 包查找谷歌搜索结果

oauth - 使用 OAuth2 保护 Flask-Restful API

javascript - Facebook 登录问题 (OAuth2)

javascript - 通过点击超链接来渲染 2 个图表

php - 使用 PHP 将文本文件插入 MySQL

api - Symfony2 api 的身份验证(供移动应用程序使用)

java - asynctask 类未将数据返回到 fragment

security - 私有(private)应用程序的 OAuth2 流程和最佳实践