tuupola / slim-jwt-auth

PSR-7 and PSR-15 JWT Authentication Middleware
https://appelsiini.net/projects/slim-jwt-auth
MIT License
827 stars 141 forks source link

get attribute empty when using "ignore" endpoints #206

Closed arthurl31 closed 3 years ago

arthurl31 commented 3 years ago

I create the jwt auth config

function jwtAuth(): JwtAuthentication
{
    return new JwtAuthentication([
        'secure' => false,
        'ignore' => ['/token'],
        'secret' => env('JWT_SECRET')
    ]);
}

then in my controller if i try to: $request->getAttribute('token');

It returns NULL, but if i remove the "ignore" from the JWT configuration it returns the decoded token just fine

    return new JwtAuthentication([
        'secure' => false,
        'secret' => env('JWT_SECRET')
    ]);

Does anyone knows what is happening?

tuupola commented 3 years ago

As the name implies the middleware is not executed in the ignored routes. Since the middleware was not executed it did not write the token attribute to the $request object.