Jwt-auth: problem with lumen 5.4.27

Created on 20 Jun 2017  路  5Comments  路  Source: tymondesigns/jwt-auth

Hi,

I've been updated my lumen composer, to v5.4.27, before this I had v5.4.19 and It was good, I got no error. The error is:

(1/1) JWTException
The token could not be parsed from the request
in JWT.php (line 176)
at JWT->parseToken()

I'm using v1.0.0-beta.3
"tymon/jwt-auth": "^1.0@dev",

Thank you.

Most helpful comment

It seems to be that the parser does not know the request variable anymore.

Edit: I forgot to mention that this solution is located in the JWTGuard.php file.

Before the following code snippet

        if ($this->jwt->getToken() && $this->jwt->check()) {
            $id = $this->jwt->payload()->get('sub');

            return $this->user = $this->provider->retrieveById($id);
        }

Add the following code line:

$this->jwt->parser()->setRequest($this->request);

By this the parser that is looking for the request headers can now read the headers again. Somehow when the parser is initialized the current request object is not send to the parser at runtime (it keeps working with a default empty request).

Hopefully the creator of the package has a solution for this matter. Meanwhile this solution works and I'm able to test JWT with Lumen. If this is a correct solution? I'm not sure because I'm still learning laravel / lumen etc :-) ...

All 5 comments

Same problem here

It seems to be that the parser does not know the request variable anymore.

Edit: I forgot to mention that this solution is located in the JWTGuard.php file.

Before the following code snippet

        if ($this->jwt->getToken() && $this->jwt->check()) {
            $id = $this->jwt->payload()->get('sub');

            return $this->user = $this->provider->retrieveById($id);
        }

Add the following code line:

$this->jwt->parser()->setRequest($this->request);

By this the parser that is looking for the request headers can now read the headers again. Somehow when the parser is initialized the current request object is not send to the parser at runtime (it keeps working with a default empty request).

Hopefully the creator of the package has a solution for this matter. Meanwhile this solution works and I'm able to test JWT with Lumen. If this is a correct solution? I'm not sure because I'm still learning laravel / lumen etc :-) ...

I have the same problem.

Adding the line to JWTGuard.php worked:
$this->jwt->parser()->setRequest($this->request);

Please fix.

Yup, seems Lumen has lost access to the request in the function "registerTokenParser()" in "AbstractServiceProvider.php" the $app['request'] is empty.

Further testing shows that this is broken in 5.4.2 but works in 5.4.1, so another fix is to mark the laravel/lumen-framework in composer.json to stick to 5.4.1 then do composer update

closed by #1243

Was this page helpful?
0 / 5 - 0 ratings