Download the PHP package malvik-lab/laravel-jwt without Composer
On this page you can find all versions of the php package malvik-lab/laravel-jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download malvik-lab/laravel-jwt
More information about malvik-lab/laravel-jwt
Files in malvik-lab/laravel-jwt
Package laravel-jwt
Short Description JSON Web Token Authentication for Laravel
License MIT
Informations about the package laravel-jwt
Laravel JWT
Laravel JWT is an open-source library for Laravel that adds JWT authentication to your project.
JWT is a token-based authentication method that is secure, lightweight, and easy to implement.
The library is easy to use and can be configured in minutes. It provides a range of features for JWT authentication, including:
- Generating and validating JWT tokens
- Managing users and tokens
- Protecting routes and controllers
Pre-installation (not mandatory)
JWT uses a pair of public and private keys to sign and verify tokens. The public key is used to verify tokens on the client side, while the private key is used to sign tokens on the server side.
The library by default stores the public and private keys in a folder called keys in the root of your project. You can change the location of this folder by adding the following to your .env file:
Library installation
This command will install the library and all its dependencies.
Publishing the configuration
This file contains the library configuration, such as the token signing method, token lifetime, and JWT key path.
Migration publication
This file creates the jwt_tokens table in your database. This table is used to store issued JWT tokens.
Running the migration
This command will create the jwt_tokens table in your database.
JWT key generation
this command will generate a public and private key pair, which will be used to sign and verify JWT tokens.
Add Guards
Add new guards to auth configuration file.
Enable API authentication with JWT
Routes
To test JWT authentication, you can add routes to your project that allow you to authenticate with a valid JWT token.
Controller
For basic use you can use MalvikLab\LaravelJwt\Http\Controllers\AuthController (as in the previous example) or use a custom controller for greater control of the authentication logic.
Recommended but not mandatory
To ensure a JSON response is always returned, it is recommended to do the following:
Add render method
Add AcceptJson middleware
Installation complete
Now that you have installed the Laravel JWT library, you can start using its features. Here are some examples of requests and responses that you can use to test JWT authentication.
Login
Request
Response
Me
Request
Response
Refresh token
Request
Response (Same as the login response)
Logout
Request
Response