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

Using integers for registered date claims is deprecated, please use DateTimeImmutable objects instead. #1381

Closed
abdallhsamy opened this issue Nov 25, 2020 · 25 comments
Labels

Comments

@abdallhsamy
Copy link

abdallhsamy commented Nov 25, 2020

  • Passport Version: 10.0.x
  • Laravel Version: 8.x.x
  • PHP Version: 7.4.x
  • Database Driver & Version: Mysql 8.x

Description:

This Error Appears

{
    "message": "Using integers for registered date claims is deprecated, please use DateTimeImmutable objects instead.",
    "exception": "ErrorException",
    "file": "/home/abdallhsamy/code/backend/vendor/lcobucci/jwt/src/Builder.php",
    "line": 151,
    "trace": [
        {
            "function": "handleError",
            "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/lcobucci/jwt/src/Builder.php",
            "line": 151,
            "function": "trigger_error"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/lcobucci/jwt/src/Builder.php",
            "line": 214,
            "function": "convertToDate",
            "class": "Lcobucci\\JWT\\Builder",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/league/oauth2-server/src/Entities/Traits/AccessTokenTrait.php",
            "line": 48,
            "function": "issuedAt",
            "class": "Lcobucci\\JWT\\Builder",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/league/oauth2-server/src/Entities/Traits/AccessTokenTrait.php",
            "line": 61,
            "function": "convertToJWT",
            "class": "Laravel\\Passport\\Bridge\\AccessToken",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/league/oauth2-server/src/ResponseTypes/BearerTokenResponse.php",
            "line": 31,
            "function": "__toString",
            "class": "Laravel\\Passport\\Bridge\\AccessToken",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/league/oauth2-server/src/AuthorizationServer.php",
            "line": 202,
            "function": "generateHttpResponse",
            "class": "League\\OAuth2\\Server\\ResponseTypes\\BearerTokenResponse",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/passport/src/PersonalAccessTokenFactory.php",
            "line": 117,
            "function": "respondToAccessTokenRequest",
            "class": "League\\OAuth2\\Server\\AuthorizationServer",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/passport/src/PersonalAccessTokenFactory.php",
            "line": 72,
            "function": "dispatchRequestToAuthorizationServer",
            "class": "Laravel\\Passport\\PersonalAccessTokenFactory",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/passport/src/HasApiTokens.php",
            "line": 67,
            "function": "make",
            "class": "Laravel\\Passport\\PersonalAccessTokenFactory",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/app/Http/Controllers/API/Auth/AuthAPIController.php",
            "line": 38,
            "function": "createToken",
            "class": "App\\Models\\Users\\User",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
            "line": 54,
            "function": "login",
            "class": "App\\Http\\Controllers\\API\\Auth\\AuthAPIController",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
            "line": 45,
            "function": "callAction",
            "class": "Illuminate\\Routing\\Controller",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 254,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\ControllerDispatcher",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 197,
            "function": "runController",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 692,
            "function": "run",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 128,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/app/Http/Middleware/RedirectIfAuthenticated.php",
            "line": 26,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "App\\Http\\Middleware\\RedirectIfAuthenticated",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
            "line": 41,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
            "line": 127,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
            "line": 63,
            "function": "handleRequest",
            "class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 103,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 694,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 669,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 635,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 624,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 166,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 128,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/fruitcake/laravel-cors/src/HandleCors.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Fruitcake\\Cors\\HandleCors",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php",
            "line": 87,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/fruitcake/laravel-cors/src/HandleCors.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Fruitcake\\Cors\\HandleCors",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Middleware.php",
            "line": 45,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Sentry\\Laravel\\Tracing\\Middleware",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 103,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 141,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 110,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/code/backend/public/index.php",
            "line": 16,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/abdallhsamy/.config/composer/vendor/genesisweb/valet-linux-plus/server.php",
            "line": 276,
            "function": "require"
        }
    ]
}

Steps To Reproduce:

after tracing error : I found that passport package depends on lcobucci/jwt that made major update in these classes
lcobucci/jwt/src/Signer/BaseSigner.php

@Linij
Copy link

Linij commented Nov 25, 2020

https://github.com/lcobucci/jwt/blob/3.4.0/src/Builder.php update 9 hours ago

  /**
     * @param int|DateTimeImmutable $value
     *
     * @return DateTimeImmutable
     */
    private function convertToDate($value)
    {
        if (! $value instanceof DateTimeImmutable) {
            trigger_error('Using integers for registered date claims is deprecated, please use DateTimeImmutable objects instead.', E_USER_DEPRECATED);

            return new DateTimeImmutable('@' . $value);
        }

        return $value;
    }

In your project composer.json add "lcobucci/jwt": "3.3.3" and execute composer update.

@l0rb
Copy link

l0rb commented Nov 25, 2020

Can confirm that this is because "lcobucci/jwt" upgraded to 3.4 with a lot of breaking changes. Downgrading this to 3.3.3 fixes the issue.

@andrewmclagan
Copy link

Sorry @Linij do not understand your comment.

Also seeing this a few minutes ago.

  • Passport Version: 9.0.x
  • Laravel Version: 7.x.x
  • PHP Version: 7.4.x
  • Database Driver & Version: Mysql 8.x

@Linij
Copy link

Linij commented Nov 25, 2020

In your project composer.json add "lcobucci/jwt": "3.3.3" and execute composer update. @andrewmclagan

@andrewmclagan
Copy link

Screen Shot 2020-11-25 at 9 19 28 pm

@Linij That solved the issue. Thank you! What downstream packages requires this?

@Linij
Copy link

Linij commented Nov 25, 2020

image

@andrewmclagan
Copy link

Ok, composer info laravel/passport -t beats wading through vendors. You just made my day, had no idea that command existed.

@Sephster
Copy link
Contributor

These errors shouldn't be showing on production. If you have these turned on, update your php.ini file to change the error level 👍

@andrewmclagan
Copy link

Was caught in CI long before prod.

@Sephster
Copy link
Contributor

It won't be a problem in prod if you have these errors suppressed. If your CI is for prod it should probably be suppressed in that build env too

@Linij
Copy link

Linij commented Nov 25, 2020

@andrewmclagan Also an instruction composer why lcobucci/jwt could know who use that package

@lagbox
Copy link

lagbox commented Nov 25, 2020

there seems to be multiple different problems with lcobucci/jwt that are popping up now that they released 3.4.0
@driesvints

@driesvints
Copy link
Member

This is a deprecation notice and these shouldn't be enabled on production. lcobucci/jwt 3.4 will be supported through #1373 which will be merged tomorrow at the latest.

@driesvints
Copy link
Member

I want to investigate something: is this exception thrown with error_reporting set to 0?

@driesvints
Copy link
Member

I've discovered that these exceptions are handled a little differently in Laravel. I'll try to investigate that more thoroughly in the upcoming days/weeks. In the meantime please stick onto lcobucci/jwt 3.3 until we merge the open PR.

@ok200paul
Copy link

TIL about composer info - thanks @Linij !

@driesvints
Copy link
Member

I've just released v10.1.0 with support for OAuth2 Server v8.2.0 and JWT v3.4.0/v4.0.0 that should fix these issues. Please update 🙂

@mludi
Copy link

mludi commented Nov 26, 2020

Lol what a timing, ran into this issue 10 minutes ago. Thanks @driesvints :-)

@l0rb
Copy link

l0rb commented Nov 26, 2020

@driesvints will there also be a patch for version 9? Laravel 6 still has support for about a year, and it can't use passport>9

@driesvints
Copy link
Member

@l0rb that's reasonable. However, if we do that we'll have to drop PHP 7.2 support for Passport v9.

I've sent in a PR with additional info here: #1387

@egbodofo
Copy link

I added "lcobucci/jwt": "3.3.3" to my project and it worked, thank you!

@JC5
Copy link

JC5 commented Nov 28, 2020

I upgraded Passport to 10.1.0 and it worked, thanks guys.

@driesvints
Copy link
Member

I've just released v9.4.0 which supports PHP 8

@exeptionerror
Copy link

hiroki-it added a commit to hiroki-it/ddd-backend-with-laravel that referenced this issue Jan 29, 2021
hiroki-it added a commit to hiroki-it/ddd-backend-with-laravel that referenced this issue Apr 4, 2021
TAnas0 added a commit to TAnas0/tutorials-api-auth that referenced this issue Aug 7, 2023
This is a fix of an error raised when calling $user()->createToken().
See the following for further details on the bug and fix:
- laravel/passport#1381
- https://stackoverflow.com/questions/65017721/laravel-passport-target-lcobucci-jwt-parser-is-not-instantiable-while-buildin
@muajjamhossain
Copy link

just add In composer.json "lcobucci/jwt": "3.3.3" and execute composer update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests