该请求缺少必需的参数,包括无效的参数值

时间:2018-12-20 07:48:04

标签: laravel-5.5

我得到了与此类似的代码,

Laravel Passport API call code parameter null

具体来说,我得到的错误是

Client error: `POST http://crateclub.oo/oauth/token` resulted in a `400 Bad Request` response: {"error":"invalid_request","message":"The request is missing a required parameter, includes an invalid parameter value, (truncated...)

这里是代码,

public function generateBearerToken()
{
    $guzzle = new \GuzzleHttp\Client;

    $response = $guzzle->post(config('app.url') . '/oauth/token', [
        'form_params' => [
            'grant_type'    => 'client_credentials',
            'client_id'     => env('PASSPORT_CLIENT_ID'),
            'client_secret' => env('PASSPORT_CLIENT_SECRET'),
            'scope'         => '',
        ],
    ]);

    $bearer_token = json_decode((string)$response->getBody(), true)['access_token'];
    $expires_in_seconds = json_decode((string)$response->getBody(), true)['expires_in'];

    $expires_at = Carbon::now()->addSecond($expires_in_seconds);

    $newToken = ApiTokenModel::create([
        'bearer_token' => $bearer_token,
        'expires_at' => $expires_at
    ]);

    return $newToken;
}

有人知道如何解决此问题吗?

0 个答案:

没有答案