Download the PHP package martin6363/laravel-api-auth without Composer
On this page you can find all versions of the php package martin6363/laravel-api-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download martin6363/laravel-api-auth
More information about martin6363/laravel-api-auth
Files in martin6363/laravel-api-auth
Package laravel-api-auth
Short Description Professional, configuration-driven API authentication package for Laravel 12+ using Sanctum
License MIT
Informations about the package laravel-api-auth
Laravel API Auth
A professional, configuration-driven API authentication package for Laravel 11 & 12+ using Laravel Sanctum. Built with clean architecture principles and designed for easy customization.
โจ Features
- ๐ Complete Authentication Flow: Registration, Login, Logout
- ๐ Dynamic Identification: Login using email, username, or any custom field
- ๐ Token Management: Access tokens with refresh capability
- ๐ Password Management: Forgot password and reset password functionality
- โ๏ธ Email Verification: Built-in email verification support (Queueable & Customizable)
- ๐ค User Profile: Get authenticated user profile endpoint
- ๐ก๏ธ Rate Limiting: Configurable rate limiting for security
- โ๏ธ Highly Configurable: Extensive configuration options
- ๐๏ธ Clean Architecture: Service-oriented design for easy extension
- ๐งช Test Ready: Built with testing in mind
๐ Requirements
- PHP >= 8.2+
- Laravel >= 11.0 or >= 12.0
- Laravel Sanctum >= 4.0
๐ Installation
Step 1: Install via Composer
Step 2: Install Laravel Sanctum (if not already installed)
Step 3: Install the Package
This command will:
- Publish the configuration file to
config/api-auth.php - Check for Laravel Sanctum installation
- Optionally run migrations
๐๏ธ > Uninstallation
If you need to remove the package and all its published components (config, controllers, services, etc.), run:
Step 4 (Optional): Publish Logics (Controllers, Services)
- If you want to customize the internal logic of the authentication (e.g., change the registration logic or add custom responses), you can publish the controllers, services to your application:
Step 5: Configure Your User Model
Ensure your User model uses the HasApiTokens trait from Laravel Sanctum:
Step 6: Configure Email (Optional)
If you're using email verification or password reset, configure your email settings in .env:
โ๏ธ Configuration
After installation, you can customize the package behavior by editing config/api-auth.php:
User Model
Token Configuration
Route Configuration
Email Verification
Email Theme Customization
- Customize the look and feel of your verification emails directly from the config.
Password Configuration
Rate Limiting
๐ก API Endpoints
Public Endpoints
Register
Response:
Login
Response:
Login Configuration (Dynamic Identification)
- You can allow users to log in using different fields (e.g., either email or username).
Forgot Password
Reset Password
Protected Endpoints (Require Authentication)
All protected endpoints require the Authorization header:
Get Profile
Response:
Refresh Token
Response:
Logout
Response:
Send Email Verification
Verify Email
๐ง Customization
Adding Custom Fields to Registration
You can easily add custom fields to the registration process by adding them to the validation configuration. The package will automatically:
- Validate the fields during registration
- Save them to the database
- Include them in API responses
Example: Adding a phone number field
-
Update your
config/api-auth.php: -
Make sure your User model's
$fillablearray includes the new field: - The field will now be automatically:
- Validated during registration
- Saved to the database
- Included in API responses
Example Registration Request:
Customizing Validation Rules
Edit config/api-auth.php:
Note:
- The
emailfield automatically gets auniquerule for registration - The
passwordfield automatically getsmin_lengthandconfirmedrules based on config - All other fields use the rules you specify exactly as configured
Extending Services
You can extend the services by binding your own implementations in a service provider:
Customizing Routes
You can disable specific routes in the configuration:
Or modify the route prefix:
๐ก๏ธ Security Features
- Rate Limiting: Prevents brute force attacks
- Password Hashing: Uses Laravel's secure password hashing
- Token Revocation: Tokens are revoked on password reset
- Email Verification: Optional email verification for new users
- CSRF Protection: Built-in CSRF protection for web routes
๐งช Testing
The package includes test examples. Run tests with:
Or with Pest:
Publish Logic
- [!IMPORTANT] Most of the package's behavior is controlled via the config/api-auth.php file. You should only publish and modify these files if you need to implement custom logic that cannot be achieved through configuration.
๐ License
This package is open-sourced software licensed under the MIT license.
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ง Support
For issues, questions, or contributions, please open an issue on the GitHub repository.
๐ Credits
Built with โค๏ธ for the Laravel community.