Download the PHP package zendrop/laravel-jwt without Composer
On this page you can find all versions of the php package zendrop/laravel-jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-jwt
Laravel JWT Guard
This package provides a simple way to use JWT (JSON Web Tokens) as an authentication guard in a Laravel application.
Installation
Require package zendrop/laravel-jwt
Setup
After installation, you need to add service provider to your config/app.php
and publish the package configuration with command
Don't forget to run migrations
Configuration
Modify the generated config/laravel-jwt.php in the config folder to suit your needs:
- Algorithm: Set the JWT algorithm you wish to use (default is HS256).
- Keys: Specify the encode and decode keys. By default, it uses the APP_KEY from your Laravel .env file.
- Payload: Configure issuer (iss) and time-to-live (ttl) for the JWT.
- Blacklist Driver: Specify the driver used for handling blacklisted tokens (default is a database driver).
Signing key rotation
The decode key accepts a comma-separated list, so the signing key can be rotated without invalidating tokens that are already in the wild:
New tokens are signed with the encode key. On verification the keys are tried in order, so the first decode key must match the encode key; the rest are fallbacks for previously issued tokens. Once the old tokens have drained, remove the old key from the list.
Whenever a token is verified by a fallback key (any key other than the first one), the package
dispatches a Zendrop\LaravelJwt\Events\JwtDecodedUsingFallbackKey event carrying the decoded
Jwt and the matched key index. Listen to it to track how much traffic still relies on the
old key before withdrawing it.
Usage
HasJwt Trait
Include the HasJwt trait in your User model or any other authenticatable model:
This provides the makeJwt() method to generate JWT for the user.
JWT Guard
In your auth.php config file, you can define the JWT guard:
For stateful JWT: