A package to implement easy authentication in lumen

dev-master 2019-01-18 18:15 UTC

This package is auto-updated.

Last update: 2020-07-14 17:24:28 UTC


LumenAuth is a simple authentication package for lumen. This enables user to get rid of primary hassle to setup token based authentication in lumen.


  • Install LumenAuth with composer:
composer require abdurrahmanriyad/lumenauth
  • Add the following line to bootstrap/app.php file
  • Add a secret key(anything you want) to LUMEN_AUTH_SECRET in .env which used to build token

eg. LUMEN_AUTH_SECRET=7852ef15dcdd3eaeb40sdfasdf459171556
  • If your User model doesn't belong to App\User then add the following line on your .env file

eg. USER_MODEL=App\Models\User


  • Add lumenAuth middleware to routes you want authentication

For example,

$router->group(['middleware' => 'lumenAuth'],
    function () use ($router) {
        //your routes
  • To generate token for a user you use LumenAuthFacade::getToken($user) which return a token for given user instance.

For example,

use Abdurrahmanriyad\LumenAuth\Facades\LumenAuthFacade;

class AuthController extends Controller {

   public function login(Request $request) {
        //validate user and check user

        // Verify the password and generate the token
        if (Hash::check($userPassword, $user->password)) {
            return response()->json([
                'token' => LumenAuthFacade::getToken($user)
            ], 200);




Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.