简体   繁体   中英

I get “message”: “Unauthenticated” laravel passport api when I want to get user logged in

Postman API 测试

Get user method I used

   public function getUser() {
$user = Auth::user();
return response()->json(['success' => $user], $this->successStatus); 
}

Api routes

Route::prefix('v1')->group(function(){
Route::post('login', 'Api\AuthController@login');
Route::post('register', 'Api\AuthController@register');
Route::group(['middleware' => 'auth:api'], function(){
Route::post('getUser', 'Api\AuthController@getUser');
});

});

Please help me guys I m stuck I ll appreciate that

When calling routes that are protected by Passport, your application's API consumers should specify their access token as a Bearer token in the Authorization header of their request. For example, when using the Guzzle HTTP library:

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

$accessToken is the token generated by the api when logging in.

You must submit this token in all requests that require authentication in your API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM