[我使用formRequest
实例作为参数创建登录名,一旦验证了用户的访问权限,便向请求中添加需要oauth服务器的参数。
但是,我从服务器oauth收到错误:
{
"error": "unsupported_grant_type",
"error_description": "The authorization grant type is not supported by the authorization server.",
"hint": "Check that all required parameters have been provided",
"message": "The authorization grant type is not supported by the authorization server."
}
但是当我将参数实例更改为Request时,我不再收到此错误。
复制步骤:
class AuthController extends Controller
{
use ThrottlesLogins;
public function store(LoginRequest $loginRequest)
{
//$loginRequest->validated();
if ($this->hasTooManyLoginAttempts($loginRequest)) {
$this->fireLockoutEvent($loginRequest);
return $this->sendLockoutResponse($loginRequest);
}
if (Auth::attempt($this->credentials($loginRequest))){
$client = $this->getClient($loginRequest->name);
$params = [
'grant_type' => 'password',
'client_id' => $client->id,
'client_secret' => $client->secret,
'username' => $loginRequest->email,
'password' => $loginRequest->password,
'scopes' => 'fd',
];
$loginRequest->request->add($params);
$req = Request::create('oauth/token', 'POST');
$response = Route::dispatch($req)->getContent();
return $response;
}
$this->incrementLoginAttempts($loginRequest);
$this->sendFailedLoginResponse($loginRequest);
}
}
尝试将Content-Type应用程序/ x-www-form-urlencoded作为标题添加到您对'oauth / token'的请求中
$req = Request::create('oauth/token', 'POST');
$req->headers->set('Content-Type', 'application/x-www-form-urlencoded');
$response = Route::dispatch($req)->getContent();