Download the PHP package tahajaiti/jwt without Composer
On this page you can find all versions of the php package tahajaiti/jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tahajaiti/jwt
More information about tahajaiti/jwt
Files in tahajaiti/jwt
Informations about the package jwt
Kyojin JWT Package
A Laravel package for implementing JSON Web Token (JWT) authentication with a robust service layer, middleware, traits, and commands.
Features
- JWT token generation and validation
- Middleware for protected routes
- Trait for easy token creation in models
- Command-line setup tool
- Facade for convenient access
- Comprehensive error handling
Requirements
- PHP >= 8.2
- Laravel >= 11.x/ 12.x
- Composer
Installation
Install the package via Composer:
Run the setup command to configure the package:
- This will:
- Create or update your .env file with JWT variables
- Publish the configuration file to config/jwt.php
- Clear configuration and cache
Configuration
-
The package publishes a configuration file at config/jwt.php. Default values are set in the .env file:
- You can customize these in either the .env file or config/jwt.php:
Usage
Service Provider
The package automatically registers its service provider. If you need to customize it, add to bootstrap/providers.php:
Generating Tokens
Using the Trait
-
Add the HasJWT trait to your User model:
- Create a token:
Using the Facade
Middleware
Protect routes with the JWT authentication middleware:
Requests must include an Authorization header:
Or optionally you can send the token through Http Cookies as 'jwt_token'
Validating Tokens
The default middleware automatically binds the user to the Auth facade
Error Handling
The package throws two main exceptions:
- TokenNotFoundException: When no token is provided (401)
- InvalidTokenException: When token is invalid or expired (401)
Handle them in your application exception handler:
Contributing
- Fork the repository
- Create your feature branch (git checkout -b feature/name)
- Commit your changes (git commit -m 'Add new feature')
- Push to the branch (git push origin feature/name)
- Open a Pull Request
License
This package is open source do whatever.
All versions of jwt with dependencies
ext-json Version *
illuminate/auth Version ^10|^11|^12
illuminate/contracts Version ^10|^11|^12
illuminate/http Version ^10|^11|^12
illuminate/support Version ^10|^11|^12