Laravel 10 Passport:调用 oauth/token api 时遇到问题

问题描述 投票:0回答:1

我最近将 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."
}
}

我已经测试过并正在邮差工作。

laravel oauth-2.0 http-post laravel-passport laravel-10
1个回答
0
投票

你找到答案了吗?

© www.soinside.com 2019 - 2024. All rights reserved.