“错误”:“ invalid_grant” Laravel 7护照

时间:2020-05-25 10:03:53

标签: laravel laravel-passport laravel-7

我将Laravel 7和护照一起使用,但出现了一些错误

这是我的控制器

class LoginController extends Controller
{
    public function login(Request $request)
    {
        $response = Http::post(
            'http://localhost/vue-spa/public/oauth/token',
            [
                'grant_type'    => 'password',
                'client_id'     => 2,
                'client_secret' => 'Z7YFRiUQITRGkWAgCuI8rNyss7BVQJDQXMZrRWiR',
                'username'      => $request->email,
                'password'      => $request->password,
                'scope'         => '',
            ]
        );

        if ($response->clientError()) {
            return $response->json('Email atau Password Salah', 400);
        } elseif ($response->serverError()) {
            return $response->json('Server Error', 500);
        }

        return $response->body();
    }
}

我得到这样的错误

enter image description here

我必须解决这个问题

只需更换

'grant_type' => 'password'

'grant_type' => 'client_credentials'

1 个答案:

答案 0 :(得分:3)

我必须解决这个问题

只需更换

'grant_type' => 'password'

'grant_type' => 'client_credentials'