tymondesigns / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.24k stars 1.55k forks source link

jwt.auth middleware not taking custom guard #1565

Open abhisheksatre opened 6 years ago

abhisheksatre commented 6 years ago

I am using two guards. (Api and admin).

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
        ],
        'admin' => [
            'driver' => 'jwt',
            'provider' => 'clients',
        ],
    ],

My route: Route::post('/dashboard', 'Admin\Controller@create')->middleware('jwt.auth');

Issue: When I pass token to above route, jwt.auth middleware is verifying token using default guard. But I want to verify it via admin guard. How to verify token via custom guard.

Your environment

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 5.6
Package version dev-develop
PHP version 7.2

Expected behaviour

The token should verify via custom guard in middleware.(jwt.auth)

Actual behaviour

The token is getting verified by default guard in middleware.(jwt.auth)

fxxxf commented 6 years ago

You can use jwt.refresh middleware. Jwt.auth performs auth verification, but it does not have guard information when executed. Only the default guard can be used.

SamHz commented 5 years ago

I have the same problem

meitesi commented 5 years ago

me too

yurik94 commented 5 years ago

Same here, i need auth against custom guard

lun324 commented 4 years ago

this is a great solutio

https://github.com/matt-allan/blog/blob/f978a651902766d7f37578c32479058145325941/content/posts/setting-the-guard-per-route-in-laravel.md

Messhias commented 3 years ago

This is also isn't working with the new Laravel versions.

Messhias commented 3 years ago

Hello everyone, any news about that? It's almost 3 months and my guards is getting increase and this is start became a code smell.

Any clean solutions?