Setup JWT for Laravel Lumen and AngularJS

So Laravel rewarded me for being an early adopter of their Micro-Framework Lumen by stripping it of Session and Cookie functionality, forcing me to rewrite code for several sites to use JWT authentication.

If you find yourself in the same spot, below is how is how I added JWT auth, of course in a very basic form as each site I am responsible for has custom integration.

JWT Front End Code

Using Satellizer - https://github.com/sahat/satellizer for AngularJS, the setup was pretty simple:

Update .htaccess

You may or may not have to do this, I did, so I am including it for you. This enables the "Bearer" JWT authentication token to pass through in each request.

Setup JWT Backend

Using composer I installed the PHP-JWT - https://github.com/firebase/php-jwt library.

Here is example code in the controller to check, parse, encode and decode JWT tokens.

Final Thoughts

If you need help or have questions please post them below, this took a bit of time to figure out, but once I did it was pretty easy simplify and replicate.

HTH

😉

one comment ( awaiting your reply! )

  • Hello.
    I have one question, how do you tell Lumen to use the Controller for handling the login?

    -- anmaur