我最近将 Laravel 9 升级到 10,突然我的 oauth/token api 无法工作。我在验证用户凭据后调用下面的函数来获取我的访问和刷新令牌。
protected function getTokenAndRefreshToken(Request $request, String $provider) {
$client = Client::where('provider', $provider)->first();
$params = [
'grant_type' => 'password',
'client_id' => $client->id,
'client_secret' => $client->secret,
'username' => $request->email,
'password' => $request->password,
];
$request->request->add($params);
$proxy = Request::create('oauth/token', 'POST');
$response = Route::dispatch($proxy);
$content = json_decode($response->getContent(), true);
if ($response->isSuccessful()) {
return $this->successResponse($content, Controller::HTTP_OK);
} else {
return $this->errorResponse($content, Controller::HTTP_UNAUTHORIZED);
}
}
在我升级 Laravel 10 后,它一直这样回复我。此响应表明 params 未包含在 POST 请求中,但我已尝试使用其他带有 params 的 POST api 并且正在工作。
{
"message": {
"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."
}
}
你找到答案了吗?