Download the PHP package vkoori/laravel-stateless-auth without Composer
On this page you can find all versions of the php package vkoori/laravel-stateless-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-stateless-auth
JwtAuth for Laravel
A fully stateless JWT authentication guard and provider for Laravel.
Supports access/refresh tokens, automatic cookie injection, multi-source token parsing (header, query, cookie), and token revocation.
β¨ Features
- π Custom Laravel guard + provider (fully stateless)
- β»οΈ Refresh token support
- πͺ Cookie-based tokens (HttpOnly, optional)
- π© Header / Query string token support
- π Token revocation
- π‘ Simple trait-based token issuing
- β‘οΈ Octane-ready
π¦ Installation
βοΈ Configuration
Publish the config file:
This will publish config/jwt-guard.php.
also read optionally
π‘ Register the Guard & Provider
In your config/auth.php:
π€ Token Support on User Model
Your User model must use the provided trait:
π§© Custom Cache Driver for JWT Token Storage
To prevent JWT tokens from being removed during global cache clears (php artisan cache:clear), you can isolate token storage using a custom cache store.
π§ Configuration
Use one of the existing cache stores, or define a dedicated store for JWT.
-
Add a new cache store in
config/cache.php: -
Define a dedicated Redis connection in
config/database.php: - Set the custom driver on your
Authenticatablemodel using theHasApiTokenstrait:
π‘ Why This Matters
By using a dedicated Redis cache store for JWT tokens:
- php artisan cache:clear wonβt wipe out active tokens
- You can still manually clear tokens when needed:
This is especially useful when enable_revoke is set to true in your config, ensuring users are logged out securely while preserving system-wide cache stability.
π JWT Scope Middleware
This package includes a built-in JwtScopeMiddleware to restrict route access based on scopes defined in the JWT token payload.
π§ Middleware Registration
β Laravel 12+
In Laravel 12+, middleware is registered using the bootstrap/app.php:
π§± Laravel 11 and below
If you're using Laravel 11 or older, register the middleware in app/Http/Kernel.php:
β Defining Scopes in Your JWT
Make sure you include the scope claim when generating your access tokens. Example:
π Protect Routes Using Scope Middleware
You can pass multiple allowed scopes or single scope, and access will be granted if at least one matches:
β οΈ Error Handling
- If the user is unauthenticated, a 401 Unauthorized will be thrown.
- If the token lacks the required scopes, a 403 Forbidden (ScopeException) will be raised.