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

Middleware: JWT Auth #1

Closed
flowdee opened this Issue Aug 8, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@flowdee

flowdee commented Aug 8, 2018

Trying to implement the Slim JWT Auth as middleware but really struggling getting this work with your skeleton.

Creating a route for generating a token is fine. The only problem is adding the middleware correctly in order so validate route requests.

All Slim JWT auth tutorials and documentations are using a different approach of setting up middlewares. That’s why I have no idea how to solve this with your skeleton, especially the part inside the Authentication Middleware class: https://gist.github.com/flowdee/799203ac858e060826892541bc0110f5

Any idea how to get this working?

@ricardoper ricardoper self-assigned this Aug 9, 2018

@ricardoper ricardoper added bug question and removed bug labels Aug 9, 2018

@ricardoper

This comment has been minimized.

Show comment
Hide comment
@ricardoper

ricardoper Aug 9, 2018

Owner

Hello Flowdee,

Sorry for the delay...

You need to call the JWT Class directly from the middlewares.php file.

Example:

--- slim3/config/middlewares.php ---
<?php

return [
    \App\Middlewares\CorsMiddleware::class,

    (new Tuupola\Middleware\JwtAuthentication([
        "secure" => false,
        "path" => "/api",
        "secret" => "supersecretkeyyoushouldnotcommittogithub",
    ])),
];

In this example, all the routes beginning with /api needs JWT Auth.

Please, try it and give some feedback.

Best regards,
Ricardo Pereira.

Owner

ricardoper commented Aug 9, 2018

Hello Flowdee,

Sorry for the delay...

You need to call the JWT Class directly from the middlewares.php file.

Example:

--- slim3/config/middlewares.php ---
<?php

return [
    \App\Middlewares\CorsMiddleware::class,

    (new Tuupola\Middleware\JwtAuthentication([
        "secure" => false,
        "path" => "/api",
        "secret" => "supersecretkeyyoushouldnotcommittogithub",
    ])),
];

In this example, all the routes beginning with /api needs JWT Auth.

Please, try it and give some feedback.

Best regards,
Ricardo Pereira.

@flowdee

This comment has been minimized.

Show comment
Hide comment
@flowdee

flowdee Aug 9, 2018

Works like charm!

Wasn't aware that I can add those third party middlewares like described. Thought it all has to take action inside separate class files, but of course it makes sense.

Thanks @ricardoper !

flowdee commented Aug 9, 2018

Works like charm!

Wasn't aware that I can add those third party middlewares like described. Thought it all has to take action inside separate class files, but of course it makes sense.

Thanks @ricardoper !

@flowdee flowdee closed this Aug 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment