Download the PHP package ra-devs/jwt-auth without Composer
On this page you can find all versions of the php package ra-devs/jwt-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ra-devs/jwt-auth
More information about ra-devs/jwt-auth
Files in ra-devs/jwt-auth
Package jwt-auth
Short Description Universal JWT auth for Laravel (tymon/jwt-auth + ra-devs/api-json-response)
License MIT
Informations about the package jwt-auth
๐ ra-devs/jwt-auth
โจ Features
| Feature | Description |
|---|---|
| ๐ Authentication | Complete auth flow: Login, Register, Logout, Token Refresh |
| ๐ Password Reset | Secure 8-character alphanumeric codes (AโZ, 2โ9) via email |
| ๐ก๏ธ Security | Rate limiting, event logging, custom exceptions |
| ๐ Monitoring | Security event logging for audit trails |
| ๐ฏ Error Handling | Structured error responses with error codes |
| โก Performance | Database indexes, optimized queries |
| ๐งช Testing | Comprehensive test suite with >80% coverage |
| ๐ Documentation | OpenAPI spec, examples, FAQ |
| ๐ง Customizable | User model, Resources, Repositories, Notifications |
| ๐ฆ Publishable | Config, migrations, routes, views |
๐ Table of Contents
- Installation
- Quick Start
- API Endpoints
- Configuration
- Usage Examples
- Customization
- Security Features
- Frontend Integration
- Testing
- Documentation
- Contributing
๐ Installation
Step 1: Install Dependencies
Install the required packages via Composer:
Step 2: Publish Package Resources
Publish the configuration, migrations, and views:
Step 3: Configure JWT Auth
Publish and configure the base JWT package:
Step 4: Configure Auth Guard
Update your config/auth.php file:
Step 5: Run Migrations
Run the database migrations:
This will create the following tables:
password_reset_codes- Stores password reset codes- Adds
refresh_tokencolumn touserstable
๐ฏ Quick Start
1. Register a New User
Response:
2. Login
Response:
3. Access Protected Route
4. Refresh Token
The refresh token is automatically sent as an HTTP-only cookie. To refresh:
๐ก API Endpoints
All endpoints are prefixed with /api/auth by default (configurable).
| Method | Endpoint | Description | Auth Required | Rate Limit |
|---|---|---|---|---|
POST |
/login |
Authenticate user and get tokens | โ | 5/min |
POST |
/register |
Register a new user | โ | 3/min |
GET |
/me |
Get current authenticated user | โ | - |
POST |
/logout |
Logout and clear refresh token | โ | - |
POST |
/refresh |
Refresh access token via cookie | โ | 10/min |
POST |
/forgot-password |
Request password reset code | โ | 3/min |
POST |
/reset-password |
Reset password using code | โ | 3/min |
Request/Response Examples
POST /api/auth/login
**Request:** **Success Response (200):** **Error Response (401):**POST /api/auth/register
**Request:** **Success Response (201):**POST /api/auth/forgot-password
**Request:** **Success Response (200):** **Note:** For security, the response is the same whether the email exists or not.POST /api/auth/reset-password
**Request:** **Success Response (200):** **Error Response (400):**โ๏ธ Configuration
After publishing, edit config/ra-jwt-auth.php to customize the package behavior.
Route Configuration
Refresh Token Cookie
Custom Classes
Override default implementations:
Registration Fields
Customize registration validation rules:
Password Reset Settings
Rate Limits
Configure rate limiting per endpoint:
๐ก Usage Examples
Custom User Resource
Create a custom resource to control API responses:
Then update config/ra-jwt-auth.php:
Custom Repository
Override authentication logic:
Custom Password Reset Notification
Create a custom email template:
๐ก๏ธ Security Features
Rate Limiting
All endpoints are protected with configurable rate limits to prevent brute force attacks:
- Login: 5 attempts per minute
- Register: 3 attempts per minute
- Password Reset: 3 attempts per minute
- Token Refresh: 10 attempts per minute
When rate limit is exceeded, the API returns:
Security Event Logging
All authentication events are automatically logged with IP address and user agent:
- โ User login (success/failure)
- โ User registration
- โ User logout
- โ Password reset requests
- โ Password reset completion
Listen to events in your EventServiceProvider:
Error Codes
Structured error responses with error codes for programmatic handling:
| Error Code | Description |
|---|---|
INVALID_CREDENTIALS |
Wrong email/password combination |
USER_NOT_FOUND |
User does not exist |
INVALID_TOKEN |
Token is invalid or expired |
PASSWORD_RESET_CODE_EXPIRED |
Reset code has expired |
PASSWORD_RESET_CODE_INVALID |
Invalid reset code |
PASSWORD_RESET_TOO_MANY_ATTEMPTS |
Too many code verification attempts |
RATE_LIMIT_EXCEEDED |
Too many requests |
Password Reset Security
- 8-character codes using alphabet without confusing characters (no I, O, 0, 1)
- Time-limited codes (configurable expiration)
- Attempt limiting (max 5 attempts by default)
- Rate limiting on code requests (1 request per minute)
๐ Frontend Integration
Vue.js / React
See detailed integration examples in docs/EXAMPLES.md for:
- Vue.js with Pinia
- React with Context API
- Axios interceptors
- Token refresh strategies
- Error handling
Quick Example (Axios)
๐งช Testing
Run Tests
Test Coverage
The package includes a comprehensive test suite:
- โ Unit tests for services (7/7 passing)
- โ Feature tests for API endpoints (14/14 passing)
- โ Rate limiting tests (2/2 passing)
- โ Password reset service tests (7/7 passing)
Current Status: 21/21 passing (100%)
โ All tests are passing successfully! See Testing Guide for details.
๐ Documentation
- ๐ API Documentation (OpenAPI) - Complete API specification
- ๐ก Integration Examples - Vue.js, React, Axios examples
- โ Frequently Asked Questions - Common questions and solutions
- ๐ค Contributing Guidelines - How to contribute
- ๐ Changelog - Version history
๐ง Customization
Override User Model
Ensure your User model implements JWTSubject:
Custom Validation Rules
Extend the request classes to add custom validation:
Custom Routes
Override routes by publishing and editing routes/api.php, or add middleware:
๐ง Development
Local Development Setup
For local development, add the package as a path repository in composer.json:
Then require it:
Project Structure
๐ค Contributing
Contributions are welcome! Please read our Contributing Guidelines before submitting a pull request.
Quick Contribution Steps
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add/update tests
- Update documentation
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
MIT ยฉ RA Devs
All versions of jwt-auth with dependencies
illuminate/support Version >=10.0
illuminate/http Version >=10.0
illuminate/notifications Version >=10.0
illuminate/validation Version >=10.0
illuminate/database Version >=10.0
illuminate/mail Version >=10.0
tymon/jwt-auth Version ^2.0
ra-devs/api-json-response Version ^1.0