Get user data using access token in laravel passport client app

后端 未结 3 1224
刺人心
刺人心 2020-12-03 01:26

I have successfully created server.app and client.app using Laravel Passport documentation. Everything works as expected.<

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 02:01

    According to Laravel documentation, you should add route to server app (routes/api.php): $response->getBody();

    Route::get('/user', function () {
        // authenticated user. Use User::find() to get the user from db by id
        return app()->request()->user();
    })->middleware('auth:api');
    

    Make request via quzzle:

    $response = $client->request('GET', '/api/user', [
        'headers' => [
            'Accept' => 'application/json',
            'Authorization' => 'Bearer '.$accessToken,
        ],
    ]);
    echo $response->getBody();
    

提交回复
热议问题