thephpleague / oauth2-server

A spec compliant, secure by default PHP OAuth 2.0 Server
https://oauth2.thephpleague.com
MIT License
6.53k stars 1.12k forks source link

Class 'Lcobucci\Clock\SystemClock' not found and Target [Lcobucci\JWT\Parser] is not instantiable with building #1207

Closed romansorin closed 3 years ago

romansorin commented 3 years ago

Description:

This issue recently popped up in one of our projects, and I've spent the better part of a full day and a half trying to sort it out. When attempting to make an API/HTTP calls that utilize Passport/OAuth, the following errors are returned:

[2021-03-30 16:04:40] production.ERROR: Class 'Lcobucci\Clock\SystemClock' not found {"exception":"[object] (Error(code: 0): Class 'Lcobucci\\Clock\\SystemClock' not found at /var/www/laravel-swoole/vendor/league/oauth2-server/src/AuthorizationValidators/BearerTokenValidator.php:80)
[stacktrace]
#0 /var/www/laravel-swoole/vendor/league/oauth2-server/src/AuthorizationValidators/BearerTokenValidator.php(66): League\\OAuth2\\Server\\AuthorizationValidators\\BearerTokenValidator->initJwtConfiguration()
#1 /var/www/laravel-swoole/vendor/league/oauth2-server/src/ResourceServer.php(67): League\\OAuth2\\Server\\AuthorizationValidators\\BearerTokenValidator->setPublicKey()
#2 /var/www/laravel-swoole/vendor/league/oauth2-server/src/ResourceServer.php(84): League\\OAuth2\\Server\\ResourceServer->getAuthorizationValidator()
#3 /var/www/laravel-swoole/vendor/laravel/passport/src/Guards/TokenGuard.php(184): League\\OAuth2\\Server\\ResourceServer->validateAuthenticatedRequest()
#4 /var/www/laravel-swoole/vendor/laravel/passport/src/Guards/TokenGuard.php(131): Laravel\\Passport\\Guards\\TokenGuard->getPsrRequestViaBearerToken()
#5 /var/www/laravel-swoole/vendor/laravel/passport/src/Guards/TokenGuard.php(94): Laravel\\Passport\\Guards\\TokenGuard->authenticateViaBearerToken()
#6 /var/www/laravel-swoole/vendor/laravel/passport/src/PassportServiceProvider.php(285): Laravel\\Passport\\Guards\\TokenGuard->user()
#7 [internal function]: Laravel\\Passport\\PassportServiceProvider->Laravel\\Passport\\{closure}()
#8 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Auth/RequestGuard.php(58): call_user_func()
#9 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Auth/GuardHelpers.php(60): Illuminate\\Auth\\RequestGuard->user()
#10 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(63): Illuminate\\Auth\\RequestGuard->check()
#11 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(42): Illuminate\\Auth\\Middleware\\Authenticate->authenticate()
#12 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Auth\\Middleware\\Authenticate->handle()
#13 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#14 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Routing/Router.php(687): Illuminate\\Pipeline\\Pipeline->then()
#15 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Routing/Router.php(662): Illuminate\\Routing\\Router->runRouteWithinStack()
#16 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Routing/Router.php(628): Illuminate\\Routing\\Router->runRoute()
#17 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Routing/Router.php(617): Illuminate\\Routing\\Router->dispatchToRoute()
#18 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\\Routing\\Router->dispatch()
#19 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#20 /var/www/laravel-swoole/vendor/beyondcode/laravel-query-detector/src/QueryDetectorMiddleware.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#21 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): BeyondCode\\QueryDetector\\QueryDetectorMiddleware->handle()
#22 /var/www/laravel-swoole/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(60): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#23 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle()
#24 /var/www/laravel-swoole/vendor/akaunting/setting/src/Middleware/AutoSaveSetting.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#25 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Akaunting\\Setting\\Middleware\\AutoSaveSetting->handle()
#26 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#27 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#28 /var/www/laravel-swoole/app/Http/Middleware/Firewall.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#29 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\\Http\\Middleware\\Firewall->handle()
#30 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#31 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#32 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#33 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle()
#34 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(63): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#35 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle()
#36 /var/www/laravel-swoole/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#37 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\\Proxy\\TrustProxies->handle()
#38 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#39 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(140): Illuminate\\Pipeline\\Pipeline->then()
#40 /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(109): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#41 /var/www/laravel-swoole/vendor/hhxsv5/laravel-s/src/Illuminate/Laravel.php(153): Illuminate\\Foundation\\Http\\Kernel->handle()
#42 /var/www/laravel-swoole/vendor/hhxsv5/laravel-s/src/LaravelS.php(209): Hhxsv5\\LaravelS\\Illuminate\\Laravel->handleDynamic()
#43 /var/www/laravel-swoole/vendor/hhxsv5/laravel-s/src/LaravelS.php(155): Hhxsv5\\LaravelS\\LaravelS->handleDynamicResource()
#44 [internal function]: Hhxsv5\\LaravelS\\LaravelS->onRequest()
#45 /var/www/laravel-swoole/vendor/hhxsv5/laravel-s/src/Swoole/Server.php(347): Swoole\\Server->start()
#46 /var/www/laravel-swoole/vendor/hhxsv5/laravel-s/src/Console/Portal.php(158): Hhxsv5\\LaravelS\\Swoole\\Server->run()
#47 /var/www/laravel-swoole/vendor/hhxsv5/laravel-s/src/Console/Portal.php(59): Hhxsv5\\LaravelS\\Console\\Portal->start()
#48 /var/www/laravel-swoole/vendor/symfony/console/Command/Command.php(258): Hhxsv5\\LaravelS\\Console\\Portal->execute()
#49 /var/www/laravel-swoole/bin/laravels(164): Symfony\\Component\\Console\\Command\\Command->run()
#50 {main}
"}

This SystemClock issue occurs on all HTTP/API calls. When trying to sign in or register a user, such as through the Google provider, the following error is logged:

[2021-03-30 15:45:18] production.DEBUG: ERROR: Target [Lcobucci\JWT\Parser] is not instantiable while building [Laravel\Passport\PersonalAccessTokenFactory]. on: 1017 in: /var/www/laravel-swoole/vendor/laravel/framework/src/Illuminate/Container/Container.php

To the best of my knowledge, I have tried all solutions so far. Originally, we were running Passport 8.x; I downgraded the JWT version to 3.3.3, explicitly installed the Clock dependency at 2.0, and then upgraded Passport & Laravel when that did not work. Installing the Clock dependency did silence the error briefly, but I read that the issue was corrected in Passport 10.1.x and verified that my versions matched.

Prior to a couple of days ago when we sorted some other errors related to Pusher, we were not having this issue, and our implementation of granting access tokens/creating users has not changed at all.

Steps To Reproduce:

  1. Create a new Laravel 8.0 project
  2. Follow the Passport installation/implementation guide, and attempt to make an API call
  3. Make other API calls that involve the usage of Bearer tokens (such as in authorization).
Sephster commented 3 years ago

Because you are running PHP 7.4, you should be running version 4.x of the JWT package. This requires the lcobbuci/clock package. Even if you were on version 3.4.x, there is a compat class to provide this package so I'm unsure how this is occurring.

Can you check what versions are in your composer lock file for the JWT package and Clock package and report back here please? Cheers.

romansorin commented 3 years ago

I forgot to update this issue after I resolved it, but I essentially cleared my project of all additional dependencies (including Passport), removed the composer.lock file, and reinstalled dependencies one-by-one. I started with the major packages (Telescope, Horizon, Passport) and then added in my smaller dependencies, resolving any version conflicts/peer dependencies as needed.

I'm successfully on Passport 10.1 and Laravel 8 w/o any issues. Thank you though!