Replicating claims as headers is deprecated and will removed from v4.0 - Laravel Passport Problem in lcobucci/jwt package
Asked Answered
G

3

58

I'm using laravel/passport:7.5.1 package in my laravel project and recently faced with this exception. Any Idea? I temperory downgrade the lcobucci/jwt:3.4.0 package to lcobucci/jwt:3.3.3

Replicating claims as headers is deprecated and will removed from v4.0. Please manually set the header if you need it replicated.

Stack Trace:

"exception": {
  "trace": [
    "/var/www/app/vendor/lcobucci/jwt/src/Builder.php:334",
    "/var/www/app/vendor/lcobucci/jwt/src/Builder.php:185",
    "/var/www/app/vendor/lcobucci/jwt/src/Builder.php:201",
    "/var/www/app/vendor/league/oauth2-server/src/Entities/Traits/AccessTokenTrait.php:34",
    "/var/www/app/vendor/league/oauth2-server/src/ResponseTypes/BearerTokenResponse.php:28",
    "/var/www/app/vendor/league/oauth2-server/src/AuthorizationServer.php:202",
    "/var/www/app/vendor/laravel/passport/src/PersonalAccessTokenFactory.php:114",
    "/var/www/app/vendor/laravel/passport/src/PersonalAccessTokenFactory.php:71",
    "/var/www/app/vendor/laravel/passport/src/HasApiTokens.php:67",
    "/var/www/app/app/Http/Controllers/Auth/Shop/GetTokenController.php:84",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Route.php:219",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Route.php:176",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:680",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php:58",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:682",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:657",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:623",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:612",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30",
    "/var/www/app/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php:65",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53",
    "/var/www/app/vendor/app/dms-pubsub/src/Middlewares/CaptureCorrelationIdMiddleware.php:40",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53",
    "/var/www/app/app/Http/Middleware/TrimData.php:31",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53",
    "/var/www/app/vendor/fideloper/proxy/src/TrustProxies.php:57",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:62",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151",
    "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116",
    "/var/www/app/public/index.php:55"
  ],
  "class": "ErrorException",
  "file": "/var/www/app/vendor/lcobucci/jwt/src/Builder.php:334",
  "message": "Replicating claims as headers is deprecated and will removed from v4.0. Please manually set the header if you need it replicated.",
  "code": 0
}
Grace answered 25/11, 2020 at 10:43 Comment(1)
Upgrading to passport v9 resolves the issue for meOverhear
G
15

I'm deeply sorry for causing confusion or issues. Please check https://github.com/lcobucci/jwt/issues/550#issuecomment-733557709 for my full explanation on why this approach was taken and why it isn't considered a BC-break in my PoV.

Gaylordgaylussac answered 25/11, 2020 at 13:9 Comment(2)
Sorry that you're getting heat for this change, thanks for looking out for it across the interwebs and providing cross-references. I do understand where you're coming from and I kind of agree, however a breaking change is a breaking change whoever it's for... this really should have left the deprecation for 4.0 and removal in 5.0 - that follows the language convention more appropriately (at least the intent, if not the implementation)Itacolumite
Changing error reporting level is not acceptable for most users, because in 90% cases PHP don't have rights to do that. Beside of that if you set it globally and it can have impakt on other parts of application. Suppressing errors in the line of code using "@" symbol is a code smell.Blitz
A
192

This issue has forced me to know that laravel/passport uses thephpleague/oauth2-server and thephpleague/oauth2-server uses lcobucci/jwt "3.3.3".

composer require lcobucci/jwt=3.3.3

I wouldn't have bothered to check this if everything worked fine today after I ran composer update on my app.

Armourer answered 29/11, 2020 at 14:0 Comment(0)
B
21

I know how people love a copy and paste answer. I fixed this by added this code to app/Providers/AppServiceProvider.php in the boot method

if (config('app.debug')) {
    error_reporting(E_ALL & ~E_USER_DEPRECATED);
} else {
    error_reporting(0);
}

This is what the author of suggested. See @Luís Cobucci answer. Or look here: https://github.com/lcobucci/jwt/issues/550#issuecomment-733557709

If you do @Ahmed Nasser method of requiring an old version then you will probably have issues in the future.

Bissextile answered 12/4, 2021 at 1:39 Comment(4)
Yup, this worked. I prefer this over updating the jwt packageDearden
Works like a charm. Can you explain your answer please? I like to copy and paste but I like to understand what i pasted too :p.Elna
It’s basically suppressing the exception. The error itself isn’t really a problem since it’s just reporting a deprecated feature. So we just suppress deprecation messages.Bissextile
This works. Should be the best as it works without needing to downgrade.Octodecillion
G
15

I'm deeply sorry for causing confusion or issues. Please check https://github.com/lcobucci/jwt/issues/550#issuecomment-733557709 for my full explanation on why this approach was taken and why it isn't considered a BC-break in my PoV.

Gaylordgaylussac answered 25/11, 2020 at 13:9 Comment(2)
Sorry that you're getting heat for this change, thanks for looking out for it across the interwebs and providing cross-references. I do understand where you're coming from and I kind of agree, however a breaking change is a breaking change whoever it's for... this really should have left the deprecation for 4.0 and removal in 5.0 - that follows the language convention more appropriately (at least the intent, if not the implementation)Itacolumite
Changing error reporting level is not acceptable for most users, because in 90% cases PHP don't have rights to do that. Beside of that if you set it globally and it can have impakt on other parts of application. Suppressing errors in the line of code using "@" symbol is a code smell.Blitz

© 2022 - 2024 — McMap. All rights reserved.