Laravel passport - middleware client_credentials bearer token not working

1.6k views Asked by At

I have a laravel project, use Passport Client Credentials to get Bearer Tokens, I create client id and secret id using

php artisan passport:client --personal

And get

client id & secret id

and get bearer/access code from postman like this bearer code

but after call other api like this using this barear but not working

Route::middleware('client_credentials')->post('/test',[ApiController::class, 'va_bills']);

and the output just

{
    "message": "Unauthenticated."
}

But if I change the route to be a closure function its work like this

Route::middleware('client_credentials')->post('/test', function (Request $request) {
    echo 'nice';
});

output closure function

I have add this to kernel.php

protected $routeMiddleware = [
..
'client_credentials'     => \Laravel\Passport\Http\Middleware\CheckClientCredentials::class,
..

and change the driver

'api' => [
            'driver' => 'passport',//instead of token 
            'provider' => 'users',
            'hash' => false,
        ],

I have also add this to .htaccess,

RewriteCond %{HTTP:Authorization} ^(.*)

RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

but for your info I dont have .htaccess before and I run my app using php artisan serve I have read many solution but still not work,

can some one help me to out from this problem? Thank you for your time.

0

There are 0 answers