Laravel 5.1 JWT and Dingo API

Laravel 5.1 JWT and Dingo API

In previous tutorial we have seen how to install Dingo Api in  Laravel

In this tutorial we are going to see how to use JWT in Laravel.
JWT => JSON Web Token.
Manily we are using JWT for Token Based Authentication in Laravel.

Step 1 : Install JWT

Run the below command in composer

It will install the JWT package to vendor folder.

  – Installing phpseclib/phpseclib (0.3.10)
    Downloading: 100%         

  – Installing namshi/jose (5.0.2)
    Downloading: 100%         

  – Installing tymon/jwt-auth (0.5.9)
    Downloading: 100%    

phpseclib/phpseclib suggests installing ext-gmp (Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.)
phpseclib/phpseclib suggests installing pear-pear/PHP_Compat (Install PHP_Compat to get phpseclib working on PHP < 4.3.3.)
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader

Step 2 : Add JWT Service provider to app.php

And add alias array. You need to add JWTAuth and JWTFactory

Step 3 : Publish JWT

It will create jwt.php under config folder.

The jwt.php folder will look like below,

Mostly I will keep as it is.

 Step 4 : Generate Secret Key for JWT

By runing the below command it will generate Secrete Key and Will update in “JWT_SECRET” section of jwt.php file.

 Step 5 : How to check jwt Token Based Authendication.

To access JWTAuth you need Dingo Api package installed in your application

Step A : Create Routes

 Step B : Create HomeController Under Controllers Folder.


Now you can check your api by using the applications Like “Postman”;

Jwt postman

Thats it, Now you can access token based authendication like above.
If you like this article don’t forget to share and comment.