在 Laravel 5.4 文档中使用 Implicit Grant Type 时
为什么 Implicit Grant 无法工作?
遵循教程的步骤却出现了以上情况:
// 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))
{
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())
&& $request->getQueryParams()['response_type'] === 'code'
&& isset($request->getQueryParams()['client_id'])
);
}
the values of the following variables are as follows:
$request->getQueryParams():
“KEY” => “14997536295521”,
“client_id” => “1”,
“redirect_uri” => “http:
“response_type” => “token”,
“scope” => “”
作为一个效果...这段代码总是返回 false,而且代码执行回到调用函数
============================================================================================
going back to vendor\league\oauth2-server\src\AuthorizationServer.php->validateAuthorizationRequest()
public function validateAuthorizationRequest(ServerRequestInterface $request)
{
foreach ($this->enabledGrantTypes as $grantType) {
if ($grantType->canRespondToAuthorizationRequest($request)) {
return $grantType->validateAuthorizationRequest($request);
}
}
throw OAuthServerException::unsupportedGrantType();
}
============================================================================================
...在某个地方
============================================================================================
In vendor\league\oauth2-server\src\Exception\OAuthServerException.php->function unsupportedGrantType()
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);
}
看起来非常熟悉,对吧?