Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Auth guard [tymon.jwt] is not defined" with adldap2-laravel #120

Closed
Geoffry304 opened this issue Feb 11, 2022 · 13 comments
Closed

"Auth guard [tymon.jwt] is not defined" with adldap2-laravel #120

Geoffry304 opened this issue Feb 11, 2022 · 13 comments
Labels
bug Something isn't working

Comments

@Geoffry304
Copy link

Geoffry304 commented Feb 11, 2022

Subject of the issue

Auth guard [tymon.jwt] is not defined.
I got this error after upgrading to L9 and changing from tymon/jwt-auth, any idea why this is happening?
When I rollback to old package and previous version everything is working.
I can fix the problem by adding this to the auth.php config file, but this is not what I want.
'tymon' => [ 'jwt' => [ 'driver' => 'jwt', 'provider' => 'users', ] ]

Your environment:

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 9.0.1
Package version 1.4.y1
PHP version 8.1.2
@Geoffry304 Geoffry304 added the bug Something isn't working label Feb 11, 2022
@mfn
Copy link
Contributor

mfn commented Feb 11, 2022

I can fix the problem by adding this to the auth.php config file, but this is not what I want.
'tymon' => [ 'jwt' => [ 'driver' => 'jwt', 'provider' => 'users', ] ]

But isn't this required per https://laravel-jwt-auth.readthedocs.io/en/latest/quick-start/#configure-auth-guard ? 🤔

Or what's your use-case to avoid this?

@Messhias
Copy link
Collaborator

It isn't required as per the docs, but you need to specify your use-case as per @mfn mentioned.

@Geoffry304
Copy link
Author

Geoffry304 commented Feb 11, 2022

Hello maybe I wasn't clear enough.
With the old package the tymon guard isn't needed in my auth.php file. I think it is dynamically added to the guards.
With the new package I got the problem.
I know I need guards to work with the jwt driver like here.
image

Everything works fine with the old package, so no manually add of tymon to the auth.

@Mishanki
Copy link

Mishanki commented Feb 17, 2022

Tried to update laravel and got similar error

Auth driver [jwt] for guard [api] is not defined.

@Messhias
Copy link
Collaborator

Can you both share your laravel.log errors?

My guard is in that way and is working fine:

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

		'api' => [
			'driver' => 'jwt',
			'provider' => 'users',
			'hash' => false,
		],
                ....
	],

And this is my composer package version (actual version is tagging to 1.4.1):

"php-open-source-saver/jwt-auth": "^1.1", 

@Mishanki
Copy link

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

        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
            'hash' => false,
        ],
    ],
php artisan serv

   InvalidArgumentException 

  Auth driver [jwt] for guard [api] is not defined.

  at vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:97
     93▕         if (method_exists($this, $driverMethod)) {
     94▕             return $this->{$driverMethod}($name, $config);
     95▕         }
     96▕ 
  ➜  97▕         throw new InvalidArgumentException(
     98▕             "Auth driver [{$config['driver']}] for guard [{$name}] is not defined."
     99▕         );
    100▕     }
    101▕ 

      +3 vendor frames 
  4   app/Logging/Processor/UserIdProcessor.php:18
      Illuminate\Support\Facades\Facade::__callStatic("user", [])

      +11 vendor frames 
  16  [internal]:0
      Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}(Object(InvalidArgumentException))

@flavio-alves-roboyo
Copy link

I got same error after upgrading to Laravel 9.x and switched to this package.

@Geoffry304 did you got it working?

@Messhias
Copy link
Collaborator

Any update about that? I'll wait, within one week we'll close due to inactivity.

@Geoffry304
Copy link
Author

Geoffry304 commented May 31, 2022

Hello, Sorry for my late response.

The problem is still there, this is my laravel.log

[2022-05-31 08:30:00] local.ERROR: Auth guard [tymon.jwt] is not defined. {"userId":603,"exception":"[object] (InvalidArgumentException(code: 0): Auth guard [tymon.jwt] is not defined. at /var/www/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:84)
[stacktrace]
#0 /var/www/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(68): Illuminate\\Auth\\AuthManager->resolve('tymon.jwt')
#1 /var/www/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(337): Illuminate\\Auth\\AuthManager->guard('tymon.jwt')
#2 /var/www/vendor/adldap2/adldap2-laravel/src/Listeners/BindsLdapUserModel.php(47): Illuminate\\Support\\Facades\\Facade::__callStatic('guard', Array)
#3 /var/www/vendor/adldap2/adldap2-laravel/src/Listeners/BindsLdapUserModel.php(31): Adldap\\Laravel\\Listeners\\BindsLdapUserModel->isUsingAdldapProvider('tymon.jwt')
#4 /var/www/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(441): Adldap\\Laravel\\Listeners\\BindsLdapUserModel->handle(Object(Illuminate\\Auth\\Events\\Authenticated))
#5 /var/www/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(249): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}('Illuminate\\\\Auth...', Array)
#6 /var/www/vendor/php-open-source-saver/jwt-auth/src/JWTGuard.php(522): Illuminate\\Events\\Dispatcher->dispatch('Illuminate\\\\Auth...')
#7 /var/www/vendor/php-open-source-saver/jwt-auth/src/JWTGuard.php(375): PHPOpenSourceSaver\\JWTAuth\\JWTGuard->fireAuthenticatedEvent(Object(App\\Models\\User))
#8 /var/www/vendor/php-open-source-saver/jwt-auth/src/JWTGuard.php(165): PHPOpenSourceSaver\\JWTAuth\\JWTGuard->setUser(Object(App\\Models\\User))
#9 /var/www/vendor/php-open-source-saver/jwt-auth/src/JWTGuard.php(149): PHPOpenSourceSaver\\JWTAuth\\JWTGuard->login(Object(App\\Models\\User))
#10 /var/www/app/Actions/RedirectIfTwoFactorAuthenticatable.php(74): PHPOpenSourceSaver\\JWTAuth\\JWTGuard->attempt(Array)
#11 /var/www/vendor/laravel/framework/src/Illuminate/Support/helpers.php(302): App\\Actions\\RedirectIfTwoFactorAuthenticatable->App\\Actions\\{closure}(Object(App\\Models\\User))
#12 /var/www/app/Actions/RedirectIfTwoFactorAuthenticatable.php(82): tap(Object(App\\Models\\User), Object(Closure))
#13 /var/www/app/Actions/RedirectIfTwoFactorAuthenticatable.php(50): App\\Actions\\RedirectIfTwoFactorAuthenticatable->validateCredentials(Object(Illuminate\\Http\\Request))
#14 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\\Actions\\RedirectIfTwoFactorAuthenticatable->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#15 /var/www/app/Actions/EnsureLoginIsNotThrottled.php(33): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#16 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\\Actions\\EnsureLoginIsNotThrottled->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#17 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#18 /var/www/app/Http/Controllers/Auth/LoginController.php(61): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#19 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\\Http\\Controllers\\Auth\\LoginController->login(Object(Illuminate\\Http\\Request))
#20 /var/www/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('login', Array)
#21 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php(261): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\Auth\\LoginController), 'login')
#22 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php(204): Illuminate\\Routing\\Route->runController()
#23 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(721): Illuminate\\Routing\\Route->run()
#24 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#25 /var/www/app/Http/Middleware/RedirectIfAuthenticated.php(29): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#26 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\\Http\\Middleware\\RedirectIfAuthenticated->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#27 /var/www/app/Http/Middleware/RedirectIfAuthenticated.php(29): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#28 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\\Http\\Middleware\\RedirectIfAuthenticated->handle(Object(Illuminate\\Http\\Request), Object(Closure), 'api')
#29 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#30 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#31 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(126): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#32 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(62): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequest(Object(Illuminate\\Http\\Request), Object(Closure), Array)
#33 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle(Object(Illuminate\\Http\\Request), Object(Closure), '60', '1')
#34 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#35 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(723): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#36 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(698): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#37 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(662): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#38 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(651): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#39 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#40 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#41 /var/www/vendor/fruitcake/laravel-cors/src/HandleCors.php(52): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#42 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\\Cors\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#43 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#44 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#45 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#46 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#47 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#48 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#49 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#50 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#51 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#52 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#53 /var/www/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#54 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Http\\Middleware\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#55 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#56 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#57 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#58 /var/www/public/index.php(58): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#59 {main}
"}

@mfn
Copy link
Contributor

mfn commented May 31, 2022

adldap2/adldap2-laravel/src/Listeners/BindsLdapUserModel

Can you try without that, so we can make sure it's not related to that?

@Geoffry304
Copy link
Author

Ok, that did the trick, when I try without it its working.

@mfn mfn changed the title Auth guard [tymon.jwt] is not defined. "Auth guard [tymon.jwt] is not defined" with adldap2-laravel Jun 1, 2022
@mfn
Copy link
Contributor

mfn commented Jun 1, 2022

Thanks for testing/confirming! I took the liberty and adapt the title of the issue, since you're OP and this is specific to your case.

Since we see this library a drop-in replacement, I consider it's still on us to fix this. Must be something badly interacting with the booting of providers maybe or something, IDK. I'm not a user of this other lib and don't have cycles to play around with this. Maybe you can do some more debugging?

@alberto255345
Copy link

Hi, I'm facing the same issue. I'm using Laravel 9, and this error is appearing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants