Jwt-auth: Unable to publish, Class 'Tymon\JWTAuth\Providers\LaravelServiceProvider' not found

Created on 16 Mar 2017  ·  31Comments  ·  Source: tymondesigns/jwt-auth

Hi all,

I have installed "tymon/jwt-auth":"1.0.0-beta.1" on Lararel 5.3.22. tymon folder was created under vendors folder, but I still received this message
[RuntimeException] Could not scan for classes inside "tests/TestCase.php" which does not appear to be a file nor a folder

I have followed instructions in https://github.com/tymondesigns/jwt-auth/issues/513 and added
Tymon\JWTAuth\Providers\LaravelServiceProvider::class in config/app.php file and tried to run php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider" but I receive this error:

[Symfony\Component\Debug\Exception\FatalThrowableError] Class 'Tymon\JWTAuth\Providers\LaravelServiceProvider' not found

LaravelServiceProvider.php file exists in the vendors folder.
I have read all posts relating to this issue but most of them are regarding older versions and they suggests same thing want I already did.
Am I doing something wrong? Could anybody give me some advise? Any help would be highly appreciated. Thanks

stale

Most helpful comment

For Laravel 5.6 use the following steps:

change the service provider from:

Tymon\JWTAuth\Providers\LaravelServiceProvider::class,

to:

Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class,

then publish it as:

php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"

All 31 comments

You need to also add the alias to config/app.php like so:

'aliases' = [
....
//other aliases
...
'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
'JWTFactory' => Tymon\JWTAuthFacades\JWTFactory::class`
]

and then include it at the top of the PHP file you want to use it in, like

use JWTAuth;

@TomKeyte Thank you for reply, I forgot to mention that I had included aliases as well. Still trying to figure what the problem is.

@bachras I hit the same error. I removed all references to jwt-auth, then removed the package from composer, ran composer update. After success I added jwt-auth, tagged at 1.0.0-beta.2, ran composer update and then re-added references to app.php and ran composer update (just to be sure).

Finally, I ran: php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"

@dwoldo Thanks for response. I have tried installing beta 2, but i hit the same problem. I don't want to update all composer components as some packages may stop working with newer versions( I already have similar issues in the past). Do you know any other way without updating all composer packages. Thanks.

changed Class 'Tymon\JWTAuth\Providers\JWTAuthServiceProvider' to Tymon\JWTAuth\Providers\LaravelServiceProvider::class

run: php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"

Solution for Laravel 5.5:

Add library to composer.json:

"require": {
    ...
    "tymon/jwt-auth": "1.0.0-beta.3"
    ...
 },

Run this command in console:
composer update

Add provider in config/app.php:

'providers' => [
    ...
    Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
    ...
],

Add aliases in the same file `config/app.php':

'aliases' => [
    ...
    'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
    'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
    ...
],

And then run command in console:
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
next run:
php artisan jwt:secret

And you can configure JWTAuth in next steps in:
https://github.com/tymondesigns/jwt-auth/wiki/Configuration

@cieniurobot Thanks alot worked with "tymon/jwt-auth": "^0.5.12" also.

use this working
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,

I personnaly managed to cleanely install it by using "tymon/jwt-auth": "1.0.0-rc.1" in my composer.json. With Laravel 5.5.20.

Hope it helps!

Always getting In ProviderRepository.php line 208:

Class 'Tymon\JWTAuth\Providers\LaravelServiceProvider' not found in Laravel 5.6

i have the same problem as jwt-auth 0.5.12 doesnt create any

laravelServiceProvider

so kindly go to

\vendor\tymon\jwt-auth\src\Providers

and check for any

JWTAuthServiceProvider

and paste the .php file in

\app\Providers

and do composer update and then do the
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"

For Laravel 5.6 use the following steps:

change the service provider from:

Tymon\JWTAuth\Providers\LaravelServiceProvider::class,

to:

Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class,

then publish it as:

php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"

Solution for Laravel 5.6:

1.) Add library to composer.json:

"require": {
    "tymon/jwt-auth": "1.0.0-rc.2"
 },

2.) Run this command in console:

$ composer update && composer install

3.) Remove any Tymon\JWT provider from config/app.php

4.) Delete Laravel Cache folders to remove old dependencies:

Delete the files in following folders:
.../bootstrap/cache/services.php
.../bootstrap/cache/config.php

5.) And then run those commands in console:

$ php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
$ php artisan jwt:secret

@cieniurobot tested and approuved solution for v 5.5 !

@chrislow Thanks a lot! It worked for me :)

Thanks a lot! It safed for me

Upgrade to the following for Laravel >5.5

"require-dev": { "tymon/jwt-auth": "1.0.*" },

See version compatibility here

Today i have meet the same problem,and my Laravel version is 5.6.37.According to the official document ,i configuration the composer.json "tymon/jwt-auth": "1.0.0.*" and configuration the app.php service provider Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class and
aliases:
'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class
but, when i run php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider" ,received this message "Unable to publish, Class 'Tymon\JWTAuth\Providers\LaravelServiceProvider' not found " ,i try to find this file,but this file does not exist.so i change provder as "Tymon\JWTAuth\Providers\LaravelServiceProvider::class",it works,receive this message "Publishing complete.",then ,i execute "php artisan jwt:generate
" i receive this message:
“ Did you mean one of these?
event:generate
ide-helper:generate
jwt:secret
key:generate

i chose jwt:secret ,it's workds!

@chrislow thanks... LARAVEL 5.7 ok

adapted App\User by
https://blog.pusher.com/laravel-jwt
and got the token
$credentials = $request->only('email', 'password');
$token = JWTAuth::attempt($credentials)

On Laravel 5.5+, there is already a feature called package auto discovery, which means that you shouldn't run artisan vendor:publish but instead should run artisan package:discover, which in your composer.json could include the recommended scripts to be run upon composer install:

        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ]

(latest version here: https://github.com/laravel/laravel/blob/master/composer.json)

@chrislow thks a lot

Go to config/jwt.php file change following provider : for "tymon/jwt-auth": "1.0.0-rc.3"
NamshiAdapter to Namshi
IlluminateAuthAdapter to Illuminate
IlluminateCacheAdapter to Illuminate

I was having the same problem after clone... Then i commented out
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
on my config\app.php
then published the vendor and uncommented it and it worked fine

For Laravel 5.7:

1) composer.json (note we need version 1.0.0-rc.3 for laravel 5.7)

"require": {
  ...
  "tymon/jwt-auth": "1.0.0-rc.3"
  ...
 },

2) update composer

composer update

3) publish vendor

php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"

4) generate key

php artisan jwt:secret

4) add aliases in config/app.php

"aliases" => [
  ...
  'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,  
  'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
  ...
]

Solution for Laravel 5.5:

Add library to composer.json:

"require": {
    ...
    "tymon/jwt-auth": "1.0.0-beta.3"
    ...
 },

Run this command in console:
composer update

Add provider in config/app.php:

'providers' => [
    ...
    Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
    ...
],

Add aliases in the same file `config/app.php':

'aliases' => [
    ...
    'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
    'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
    ...
],

And then run command in console:
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
next run:
php artisan jwt:secret

And you can configure JWTAuth in next steps in:
https://github.com/tymondesigns/jwt-auth/wiki/Configuration

Now in 2019, this work

I had the same problem, I solved this way

I removed provider from 'config/app.php':

'providers' => [
    ...
    Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
    ...
],

I removed aliases in the same file 'config/app.php':

'aliases' => [
    ...
    'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
    'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
    ...
],

I removed 'tymon/jwt-aut' from composer require and i runned command in console:
composer update

I installed 'tymon/jwt-aut' with this command:
composer require tymon/jwt-auth dev-develop

I added provider in 'config/app.php':

'providers' => [
    ...
    Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
    ...
],

I published the package config file:
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"

And generated a key:
php artisan jwt:secret

Laravel Framework 5.8.16

just follow the steps in the documnetation

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

heroghost picture heroghost  ·  3Comments

CBR09 picture CBR09  ·  3Comments

loic-lopez picture loic-lopez  ·  3Comments

Rasoul-Karimi picture Rasoul-Karimi  ·  3Comments

shah-newaz picture shah-newaz  ·  3Comments