Skip to content

Laravel Passport always returns 401 Unauthenticated #906

@ivan-avalos

Description

@ivan-avalos

I'm driving crazy! I've been searching around the web on thousands of StackOverFlow questions and haven't solved my issue.

I'm developing an API REST with Laravel Framework 5.7 and Passport 7.0. I've setup every file following the documentation and I'm able to get a token with grant_type=password (without authentication flow), but when I try to access to a route protected by the auth:api middleware, I always get a 401 response.

This is my HTTP request:

GET /api/usuario/1/grupos HTTP/1.1
Host: localhost:8000
Accept: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI...

Here's my auth.php guard config:

'guards' => [
    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],

This is the mapApiRoutes() in my RouteServiceProvider.php:

protected function mapApiRoutes()
{
    Route::prefix('api')
         ->middleware('auth:api')
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));
}

Thanks, I hope you could help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions