Unauthenticated : Authenticate web using Laravel Passport Token-Based Authentication

  http, laravel, laravel-passport, php, redirect

Authenticate web using Laravel Passport

I’m Redirecting the Response by specifying the access token as a Bearer token in the Authorization header to the route. And getting below error.

IlluminateAuthAuthenticationException: Unauthenticated.

File: Controller.php

        $id = '1';
        $accessToken = 'passport_token_value';
        return redirect('home/id='.$id)->header('Authorization', 'Bearer '.$accessToken);

I have assigned Laravel Passport custom middleware to protect and authenticate different types of users by defining their guard.

File: routesweb.php

Route::get('home/id={id}', '[email protected]')->middleware('auth:api-custom');

File: configauth.php

'guards' => [   
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport', // set this to passport
            'provider' => 'user', //
            'hash' => false,
        ],

        'api-custom' => [
            'driver' => 'passport', // set this to passport
            'provider' => 'custom', //
            'hash' => false,
        ],
    ],

However, the above configuration is working in API through Postman.

Can we use the Laravel HTTP Client?

Thank you.

Source: Laravel

Leave a Reply