jwt-auth icon indicating copy to clipboard operation
jwt-auth copied to clipboard

Laravel 7 bug

Open Viking0607 opened this issue 4 years ago • 3 comments

Subject of the issue

Describe your issue here.

Your environment

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 7.0
Package version 1.0.0
PHP version 7.2.5

Steps to reproduce

I am trying to log in using the following method

    $credentials = $request->only(['Login', 'Password']);
    $credentials['Password'] = $this->getPasswordHash($credentials['Password']);

      $jwtCredentials = [
        'Login' => $credentials['Login'],
        'password' => $credentials['Password']
      ];
      try {
        \DB::enableQueryLog();
        $token = auth()->attempt($jwtCredentials);
        if (!$token)
          return response()->json(['message' => $jwtCredentials, 't' => $token, 'a'=> \DB::getQueryLog()], 401);
      } catch (JWTException $e) {
        return response()->json(['message' => 'Не могу создать токен'], 500);
      }

But the token gets false

As you can see in the code , I looked at which query is sent to the database. I got this

{query: "select top 1 * from [DV].[d_Mobile_Users] where [Login] = ?", bindings: ["test2017"],…}
query: "select top 1 * from [DV].[d_Mobile_Users] where [Login] = ?"
bindings: ["test2017"]
time: 190.41

In other words the password is not passed to the request.

Can you tell me what I'm doing wrong?

Viking0607 avatar Mar 18 '20 18:03 Viking0607

Hi! There is something wrong in the lib or its usage for sure.

To find out what,

 catch (JWTException $e) {
   return response()->json(['message' => 'Не могу создать токен'], 500);

I guess it is better to print out exception message and stack to know what failed. If you use example from documentation:

class AuthController extends Controller
{
    /**
     * Create a new AuthController instance.
     *
     * @return void
     */
    public function __construct()
    {
>>>     $this->middleware('auth:api', ['except' => ['login']]);
    }

Then remove this handler line of code. Thus there will be an Exception message like this:

{
    "message": "Argument 1 passed to Tymon\\JWTAuth\\JWTGuard::login() must be an instance of Tymon\\JWTAuth\\Contracts\\JWTSubject, instance of App\\User given, called in /var/www/share/website/vendor/tymon/jwt-auth/src/JWTGuard.php on line 127",
    "exception": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
    "file": "/var/www/share/website/vendor/tymon/jwt-auth/src/JWTGuard.php",
    "line": 140,
    "trace": [
        {
            "file": "/var/www/share/website/vendor/tymon/jwt-auth/src/JWTGuard.php",
            "line": 127,
            "function": "login",
            "class": "Tymon\\JWTAuth\\JWTGuard",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/app/Http/Controllers/ApiController.php",
            "line": 30,
            "function": "attempt",
            "class": "Tymon\\JWTAuth\\JWTGuard",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/app/Http/Controllers/ApiController.php",
            "line": 48,
            "function": "login",
            "class": "App\\Http\\Controllers\\ApiController",
            "type": "->"
        },
        {
            "function": "register",
            "class": "App\\Http\\Controllers\\ApiController",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
            "line": 54,
            "function": "call_user_func_array"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
            "line": 45,
            "function": "callAction",
            "class": "Illuminate\\Routing\\Controller",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 219,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\ControllerDispatcher",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 176,
            "function": "runController",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 681,
            "function": "run",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 130,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
            "line": 41,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
            "line": 59,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 105,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 683,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 658,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 624,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 613,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 170,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 130,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
            "line": 63,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 105,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 145,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 110,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/public/index.php",
            "line": 55,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/var/www/share/website/server.php",
            "line": 21,
            "function": "require_once"
        }
    ]
}

olecom avatar Apr 02 '20 09:04 olecom

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.

stale[bot] avatar Dec 25 '20 17:12 stale[bot]

A have the same problem, if you resolve this shar for us thanks!

regidias2006 avatar Jan 21 '22 00:01 regidias2006