whilesmart/laravel-user-authentication
Composer 安装命令:
composer require whilesmart/laravel-user-authentication
包简介
Package for managing user authentication across our projects
README 文档
README
A comprehensive Laravel authentication package with support for registration, login, password reset, OAuth integration, and configurable email/phone verification.
Features
-
Complete Authentication System:
- User registration with customizable fields
- Login with email, phone, or username
- Password reset functionality
- OAuth integration (Google, Apple, etc.)
-
Email/Phone Verification:
- Configurable verification before registration
- Event-driven integration with any email/SMS provider
- Built-in SmartPings integration for managed verification
- Rate limiting and security features
- 5-minute code expiry (configurable)
-
Developer-Friendly:
- OpenAPI documentation with PHP attributes
- Customizable response formatting
- Middleware hooks for custom logic
- Event system for extensibility
-
Security Features:
- Backend verification validation
- Rate limiting protection
- Secure code generation and storage
Quick Start
composer require whilesmart/laravel-user-authentication php artisan migrate
That's it! The package will auto-register routes and work out of the box.
Email/Phone Verification
Option 1: SmartPings Integration (Managed)
For hassle-free verification with SmartPings handling the entire flow:
# .env
USER_AUTH_REQUIRE_EMAIL_VERIFICATION=true
USER_AUTH_REQUIRE_PHONE_VERIFICATION=false
USER_AUTH_VERIFICATION_PROVIDER=smartpings
USER_AUTH_SELF_MANAGED=false
USER_AUTH_ROUTE_PREFIX=api
SMARTPINGS_CLIENT_ID=your-client-id
SMARTPINGS_SECRET_ID=your-secret-id
All configuration is now environment-driven for better deployment flexibility.
Option 2: Custom Provider (Self-Managed)
Set up email or phone verification with event-driven integration:
# .env
USER_AUTH_REQUIRE_EMAIL_VERIFICATION=true
USER_AUTH_REQUIRE_PHONE_VERIFICATION=false
USER_AUTH_VERIFICATION_PROVIDER=default
USER_AUTH_SELF_MANAGED=true
USER_AUTH_CODE_LENGTH=6
USER_AUTH_CODE_EXPIRY_MINUTES=5
USER_AUTH_RATE_LIMIT_ATTEMPTS=3
USER_AUTH_RATE_LIMIT_MINUTES=5
USER_AUTH_ROUTE_PREFIX=api
Create event listeners to send codes via your preferred provider:
class SendVerificationCodeEmailListener { public function handle(VerificationCodeGeneratedEvent $event) { Mail::raw("Your code: {$event->code}", function($msg) use ($event) { $msg->to($event->contact)->subject('Verification Code'); }); } }
📖 Complete Verification Setup Guide
Environment Variables
All package configuration is now environment-driven. Add these variables to your .env file:
Core Settings
# Route prefix for all authentication endpoints (default: api)
USER_AUTH_ROUTE_PREFIX=api
Verification Settings
# Email verification (default: false) USER_AUTH_REQUIRE_EMAIL_VERIFICATION=false # Phone verification (default: false) USER_AUTH_REQUIRE_PHONE_VERIFICATION=false # Verification provider: 'default' or 'smartpings' (default: default) USER_AUTH_VERIFICATION_PROVIDER=default # Self-managed verification (default: true) # Set to false when using SmartPings to let them handle the flow USER_AUTH_SELF_MANAGED=true # Verification code length (default: 6) USER_AUTH_CODE_LENGTH=6 # Code expiry time in minutes (default: 5) USER_AUTH_CODE_EXPIRY_MINUTES=5 # Rate limiting attempts before blocking (default: 3) USER_AUTH_RATE_LIMIT_ATTEMPTS=3 # Rate limiting window in minutes (default: 5) USER_AUTH_RATE_LIMIT_MINUTES=5
SmartPings Integration
# Required when USER_AUTH_VERIFICATION_PROVIDER=smartpings
SMARTPINGS_CLIENT_ID=your-client-id
SMARTPINGS_SECRET_ID=your-secret-id
Available Endpoints
POST /api/register- Register a new userPOST /api/login- User loginPOST /api/logout- User logoutPOST /api/send-verification-code- Send verification codePOST /api/verify-code- Verify submitted codePOST /api/password/reset-code- Request password resetPOST /api/password/reset- Reset passwordGET /api/oauth/{provider}/login- OAuth loginGET /api/oauth/{provider}/callback- OAuth callbackPOST /api/oauth/firebase/{provider}/callback- Firebase OAuth callback. See the Laravel Firebase Package for Firebase configurations.
Events
The package dispatches events for extensibility:
UserRegisteredEvent- After successful registrationUserLoggedInEvent- After successful loginUserLoggedOutEvent- After logoutVerificationCodeGeneratedEvent- When verification codes are generatedPasswordResetCodeGeneratedEvent- When password reset codes are generatedPasswordResetCompleteEvent- After password reset
OpenAPI Documentation
To include the authentication endpoints in your OpenAPI specification, publish the documentation class:
php artisan vendor:publish --provider="Whilesmart\UserAuthentication\UserAuthenticationServiceProvider" --tag="laravel-user-authentication-docs"
This will create app/Http/Documentation/UserAuthOpenApiDocs.php containing all OpenAPI attributes for the authentication endpoints. Your OpenAPI generator will automatically discover and include these endpoints.
Alternative: Publish specific tags
# Publish only documentation php artisan vendor:publish --tag="laravel-user-authentication-docs" # Publish only configuration php artisan vendor:publish --tag="laravel-user-authentication-config" # Publish everything php artisan vendor:publish --provider="Whilesmart\UserAuthentication\UserAuthenticationServiceProvider"
Apple Oauth
Apple Oauth is provided by SocialLite Providers. Please see the steps outlined here to configure Apple Oauth
Documentation
- 📖 Installation Guide - Complete installation instructions
- 📖 Email/Phone Verification - Set up verification with any provider
- 📖 Customization Guide - Response formatting, middleware hooks
Development Commands
composer test- Run unit testscomposer phpmd- Run Mess Detector checkscomposer phpstan- Run Static Analysis checkscomposer phpcs- Run PHP code style checkscomposer pint- Run Laravel code style checkscomposer openapi- Run open api documentation generation
License
This project is licensed under the MIT License - see the LICENSE file for details.
whilesmart/laravel-user-authentication 适用场景与选型建议
whilesmart/laravel-user-authentication 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.5k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 whilesmart/laravel-user-authentication 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 whilesmart/laravel-user-authentication 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-27