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

Only when testing ReflectionException: Class Tymon\JWTAuth\Middleware\GetUserFromToken #967

Open
taos-thiagoaos opened this issue Jan 23, 2017 · 8 comments

Comments

@taos-thiagoaos
Copy link

When i run vendor/bin/phpunit show the error

ReflectionException: Class Tymon\JWTAuth\Middleware\GetUserFromToken

/home/thiagoaos/workspace/projects/php/base/vendor/laravel/framework/src/Illuminate/Container/Container.php:741
/home/thiagoaos/workspace/projects/php/base/vendor/laravel/framework/src/Illuminate/Container/Container.php:631
/home/thiagoaos/workspace/projects/php/base/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:674
/home/thiagoaos/workspace/projects/php/base/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:142
/home/thiagoaos/workspace/projects/php/base/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php:396
/home/thiagoaos/workspace/projects/php/base/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php:71
/home/thiagoaos/workspace/projects/php/base/tests/UserTest.php:25

But the application works like a charm in develop mode.

    /**
     * The application's route middleware.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'cors' => \App\Http\Middleware\Cors::class,
        'jwt.auth' => "Tymon\JWTAuth\Middleware\GetUserFromToken",
        'jwt.refresh' => "Tymon\JWTAuth\Middleware\RefreshToken",
        'acl.role' => \App\Http\Middleware\HasRole::class,
        'acl.permission' => \App\Http\Middleware\HasPermission::class,
        'develop.auth' => \App\Http\Middleware\DevelopAuth::class
    ];

I test with class approach too

    'jwt.auth' => \Tymon\JWTAuth\Middleware\GetUserFromToken::class,
    'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class,
    'providers' => [
    ...
        Tymon\JWTAuth\Providers\LaravelServiceProvider::class
    ],
    'aliases' => [
    ...
        'JWTAuth'       => Tymon\JWTAuth\Facades\JWTAuth::class,
        'JWTFactory'    => Tymon\JWTAuth\Facades\JWTFactory::class
    ],

I was using alpha.2 (another Provider config) and now i test with this config using beta.1. Both work in development but in test throgth vendor/bin/phpunit no.

Need some config to work in test?

@gmann1982
Copy link

Getting the same error when using Laravel 5.4

Class Tymon\JWTAuth\Middleware\GetUserFromToken does not exist

@gmann1982
Copy link

Fixed by changing:

Tymon\JWTAuth\Middleware\GetUserFromToken::class

to

Tymon\JWTAuth\Http\Middleware\Authenticate::class

@taos-thiagoaos
Copy link
Author

I see that in source code :)
The middleware in alpha 2 and beta 1 change the name.
And now, don't need more do declare in kernel.php, the new Provider already did that automatically.

The strange thing is that only happened the error when i started the system by phpunit

@jacmkno
Copy link

jacmkno commented Jan 16, 2018

I had the same issue, and changing the name worked :) but for me it was also working fine before the change from outside phpunit. Does this mean that the library is loaded twice (with the old name and the new name) for calls outside phpunit? This worries me a little. Can someone help us find out why it was working from outside phpunit with the old name?

BTW. With the new name it works fine form curl and from phpunit so this is quite weird...

@gileneusz
Copy link

gileneusz commented Jun 28, 2018

@gmann1982
now it gives: Class Tymon\\JWTAuth\\Middleware\\Authenticate does not exist
LOL, I hate it

@ahmadnwira
Copy link

this worked for me
using [laravel 5.6 & jwt-auth 1.0]

'jwt.auth' => \Tymon\JWTAuth\Http\Middleware\Authenticate::class,
'jwt.refresh' => \TymonJWTAuth\MiddlewareRefreshToken::class

@tiaguinhor
Copy link

laravel 5.6+ & jwt-auth 1.0+

'jwt.auth' => \Tymon\JWTAuth\Http\Middleware\Authenticate::class,
'jwt.refresh' => \Tymon\JWTAuth\Http\Middleware\RefreshToken::class,

@purplenimbus
Copy link

purplenimbus commented Dec 25, 2020

laravel 5.6+ & jwt-auth 1.0+

'jwt.auth' => \Tymon\JWTAuth\Http\Middleware\Authenticate::class,
'jwt.refresh' => \Tymon\JWTAuth\Http\Middleware\RefreshToken::class,

This worked for me

"laravel/framework": "^7.0"
"tymon/jwt-auth": "dev-develop"

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

No branches or pull requests

7 participants