Jwt-auth: Tymon\JWTAuth\Exceptions\JWTException: Could not create token: Implicit conversion of keys from strings is deprecated. Please use InMemory or LocalFileReference classes.

Created on 25 Nov 2020  ·  26Comments  ·  Source: tymondesigns/jwt-auth

Subject of the issue

"lcobucci/jwt": "3.4.0"

https://github.com/lcobucci/jwt/releases/tag/3.4.0

⚠ This version also triggers E_USER_DEPRECATED errors in scenarios where we can't simply use @deprecated. Please make sure you follow the provided instructions before upgrading your production code.

Your environment

| Q | A
| ----------------- | ---
| Bug? | yes
| New Feature? | no
| Framework | Laravel
| Framework version | 8.x.y
| Package version | 1.x.y
| PHP version | 7.x.y

Most helpful comment

EDIT by @tymondesigns
Please install latest version to address this issue instead of switching to namshi/jose


In config\jwt.php file
Change 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class, to 'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
=> It works for me <3

All 26 comments

Please check this upgrading guide

https://lcobucci-jwt.readthedocs.io/en/latest/upgrading/#v3x-to-v4x

EDIT by @tymondesigns
Please install latest version to address this issue instead of switching to namshi/jose


In config\jwt.php file
Change 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class, to 'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
=> It works for me <3

lcobucci/jwt:3.4 has this problem, composer require lcobucci/jwt:3.3 can resolve it.

In config\jwt.php file
Change 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class, to 'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
=> It works for me <3

How to fix for Lumen ?

@wasddsaw publish jwt config file and load it in your bootstrap file with $app->configure()
-> https://github.com/laravel/lumen/blob/8.x/bootstrap/app.php#L62

In the meantime for those like me who uses lcobucci/jwt as a dependency of leage/league/oauth2-server or laravel/passport you can explicitly require the version 3.3.3 of the lcobucci/jwt package (until a better solution comes up) by executing:

composer require lcobucci/jwt:3.3.3 && composer update

It's not working for me, the lib used is "tymon/jwt-auth": "1.*"

I received the error: Could not create token: Implicit conversion of keys from strings is deprecated. Please use InMemory or LocalFileReference classes

I change my php.ini adding in the error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_USER_DEPRECATED and keep not working.

It's not working for me, the lib used is "tymon/jwt-auth": "1.*"

I received the error: Could not create token: Implicit conversion of keys from strings is deprecated. Please use InMemory or LocalFileReference classes

I change my php.ini adding in the error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_USER_DEPRECATED and keep not working.

question is what are the content of your composer.lock for lcobucci/jwt

It's not working for me, the lib used is "tymon/jwt-auth": "1.*"
I received the error: Could not create token: Implicit conversion of keys from strings is deprecated. Please use InMemory or LocalFileReference classes
I change my php.ini adding in the error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_USER_DEPRECATED and keep not working.

question is what are the content of your composer.lock for lcobucci/jwt

Hi @dcyou , thanks for reply, my content in the composer.lock is:

"url": "https://github.com/lcobucci/jwt.git",
                "url": "https://api.github.com/repos/lcobucci/jwt/zipball/c1123697f6a2ec29162b82f170dd4a491f524773",
                "lcobucci/jwt": "^3.2"

I think you don't run that command composer require lcobucci/jwt:3.3.3 if you ran that command you also should have "lcobucci/jwt": "3.3.3", in your require of composer.json

In config\jwt.php file
Change 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class, to 'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
=> It works for me <3

You are now, officially my best friend

In config\jwt.php file
Change 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class, to 'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
=> It works for me <3

This works, make sure to run php artisan config:clear after

Any solution for branch 2.0?

Any solution for branch 2.0?

downgrade lcobucci/jwt to 3.3.3

Apart from downgrading, what's the longer term solution and does package author need help to implement?

Do we need to update the package for compatibility ?

In config\jwt.php file
Change 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class, to 'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
=> It works for me <3

Hi, i had the same issue and i tested this solutions and now it works fine !!! Thanks a lot for your help

thanks, it's work!

In config\jwt.php file
Change 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class, to 'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
=> It works for me <3

Hi, i had the same issue and i tested this solutions and now it works fine !!! Thanks a lot for your help

I changed this and it' work, But response throw 401 when call refresh token api

In config\jwt.php file
Change 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class, to 'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
=> It works for me <3

That worked. I am using Laravel 8 :+1:

I change my php.ini adding in the error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_USER_DEPRECATED and keep not working.

All Laravel versions override the server error_reporting configuration. I've created https://github.com/laravel/framework/pull/35381 to address this issue and not break apps on deprecation messages from any library.

I really hope that gets merged and helps you all :+1:

Just catching up on all this. Looks like an upgrade to v4 is necessary, so will work on that asap. Thanks all!

@tymondesigns feel free to ping on PRs about this, would gladly help reviewing them 👍

Please check your PHP version requirements, v4 is PHP 7.4+ only. If need to support older PHP versions, you'd need to use ^3.4 || ^4.0 as version constraint. https://lcobucci-jwt.readthedocs.io/en/stable/upgrading/ should help you to achieve that.

@tymondesigns feel free to ping on PRs about this, would gladly help reviewing them 👍

Please check your PHP version requirements, v4 is PHP 7.4+ only. If need to support older PHP versions, you'd need to use ^3.4 || ^4.0 as version constraint. lcobucci-jwt.readthedocs.io/en/stable/upgrading should help you to achieve that.

Thanks, I think the best course of action is to restrict the version to <3.4 for now. I can address the v4 upgrade in the 2.0 branch, where php 7.4 is the minimum.

Closing as release has been tagged to address this https://github.com/tymondesigns/jwt-auth/releases/tag/1.0.2

Thanks @tymondesigns !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kofi1995 picture kofi1995  ·  3Comments

gandra picture gandra  ·  3Comments

functionpointdaniel picture functionpointdaniel  ·  3Comments

heroghost picture heroghost  ·  3Comments

marciomansur picture marciomansur  ·  3Comments