tymondesigns / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.27k stars 1.55k forks source link

Unable to publish, Class 'Tymon\JWTAuth\Providers\LaravelServiceProvider' not found #1038

Open bachras opened 7 years ago

bachras commented 7 years ago

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

TomKeyte commented 7 years ago

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;
bachras commented 7 years ago

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

dwoldo commented 7 years ago

@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"

bachras commented 7 years ago

@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.

fredroo commented 7 years ago

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

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

cieniurobot commented 6 years ago

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

achchu93 commented 6 years ago

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

kobidkunda commented 6 years ago

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

guillaume-raineri commented 6 years ago

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!

maneeshms commented 6 years ago

Always getting In ProviderRepository.php line 208:

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

anikethsaha commented 6 years ago

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"

hmamman commented 6 years ago

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"
chrislow commented 6 years ago

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
Newtypcr commented 6 years ago

https://github.com/tymondesigns/jwt-auth/issues/url

P4Thi0ut commented 6 years ago

@cieniurobot tested and approuved solution for v 5.5 !

timolinn commented 6 years ago

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

bizongmun commented 6 years ago

Thanks a lot! It safed for me

SirDannyMunn commented 6 years ago

Upgrade to the following for Laravel >5.5

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

See version compatibility here

Jason-Nake commented 6 years ago

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!

stafin commented 5 years ago

@chrislow thanks... LARAVEL 5.7 ok

avrahamm commented 5 years ago

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

itsnotvalid commented 5 years ago

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)

aymard229 commented 5 years ago

@chrislow thks a lot

mugisham commented 5 years ago

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

aomini commented 5 years ago

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

tsogi commented 5 years ago

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, ... ] ```
gjae commented 5 years ago

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

ciarlystreet commented 5 years ago

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

laravel10 commented 4 years ago

This worked for me: https://jwt-auth.readthedocs.io/en/docs/laravel-installation/

laravel10 commented 4 years ago

just follow the steps in the documnetation

stale[bot] commented 3 years ago

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.