繁体   English   中英

隐式授予Laravel 5.4护照unsupported_grant_type错误

[英]Implicit grant Laravel 5.4 passport unsupported_grant_type error

我已经成功使用护照2.0和laravel 5.4实现了授权码授予和密码授予。 添加Passport :: enableImplicitGrant();之后; 在AuthServiceProvider.php中,我尝试使用angular2应用程序实现隐式授予。

  getImplicitAccessToken() {
    const headers = new Headers({
      'Content-Type': 'application/json',
      'Accept' : 'application/json'
    });
    const query = {
      'grant_type' : 'token',
      'client_id' : Constants.IMPLICIT_TEST_CLIENT_ID,
      'redirect_uri' : window.location.origin + '/implicit-code-grant',
      'scope': ''
    };
    const params = this.getParamsFromJson(query);
    window.location.href = Constants.OAUTH_AUTHORIZATION_URL + '?' + params.toString();
  }
  private getParamsFromJson(query: any) {
    const params = new URLSearchParams();
    for (const key in query) {
      params.set(key, query[key]);
    }
    return params;
  }

但是我收到unsupported_grant_type错误

在Laravel 5.4文档上进行隐式授予类型时,答案:

为什么隐式补助金不起作用

遵循本教程的结果:

// 20170711152854
// http://oauth2server1/oauth/authorize?KEY=14997536295521&client_id=1&redirect_uri=http%3A%2F%2Fauthorizationgrantclient1%2Fcallback&response_type=token&scope=%3FXDEBUG_SESSION_START%3DECLIPSE`enter code here`_DBGP

    {
      "error": "unsupported_grant_type",
      "message": "The authorization grant type is not supported by the authorization server.",
      "hint": "Check the `grant_type` parameter"
    }

============================================================================================

在隐式授予令牌请求代码中,它正在请求: http:// oauth2server1 / oauth / authorize ?$ query

============================================================================================

oauth / authorize GET请求的处理程序为:Laravel \\ Passport \\ Http \\ Controllers \\ AuthorizationController @ authorize根据php artisan route:list

============================================================================================

…某处

============================================================================================

In vendor\league\oauth2-server\src\AuthorizationServer.php -> function validateAuthorizationRequest()

    /**
     * Validate an authorization request
     *
     * @param ServerRequestInterface $request
     *
     * @throws OAuthServerException
     *
     * @return AuthorizationRequest
     */
    public function validateAuthorizationRequest(ServerRequestInterface $request)
    {
        foreach ($this->enabledGrantTypes as $grantType)
        {
            if($grantType->canRespondToAuthorizationRequest($request)) // <— ValidationStartsHere
            {
                return $grantType->validateAuthorizationRequest($request);
            }
        }

        throw OAuthServerException::unsupportedGrantType();
    }

============================================================================================

…某处

============================================================================================

In vendor/league/oauth2-server/src/Grant/AuthCodeGrant.php -> function canRespondToAuthorizationRequest()

    /**
     * {@inheritdoc}
     */
    public function canRespondToAuthorizationRequest(ServerRequestInterface $request)
    {
        return (array_key_exists('response_type', $request->getQueryParams())  // TRUE
                && $request->getQueryParams()['response_type'] === 'code'      // FALSE
                && isset($request->getQueryParams()['client_id'])              // TRUE
        );
    }

the values of the following variables are as follows:
$request->getQueryParams():
“KEY”           => “14997536295521”,
“client_id”     => “1”,
“redirect_uri”  => “http://authorizationgrantclient1/callback”, // refer this value back to how to make an        implicit grant token request
“response_type” => “token”,
“scope”         => “”

实际上,此代码始终返回false,代码执行返回到调用函数

============================================================================================

going back to vendor\league\oauth2-server\src\AuthorizationServer.php->validateAuthorizationRequest()

    /**
     * Validate an authorization request
     *
     * @param ServerRequestInterface $request
     *
     * @throws OAuthServerException
     *
     * @return AuthorizationRequest
     */
    public function validateAuthorizationRequest(ServerRequestInterface $request)
    {
        foreach ($this->enabledGrantTypes as $grantType) {
            if ($grantType->canRespondToAuthorizationRequest($request)) {
                return $grantType->validateAuthorizationRequest($request);
            }
        }

        throw OAuthServerException::unsupportedGrantType(); // <—looks familiar?
    }

============================================================================================

…下线的某个地方

============================================================================================

In vendor\league\oauth2-server\src\Exception\OAuthServerException.php->function unsupportedGrantType()

    /**
     * Unsupported grant type error.
     *
     * @return static
     */
    public static function unsupportedGrantType()
    {
        $errorMessage = 'The authorization grant type is not supported by the authorization server.';
        $hint = 'Check the `grant_type` parameter';

        return new static($errorMessage, 2, 'unsupported_grant_type', 400, $hint);
    }

看起来很熟悉吧?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM