patrikjak/auth
Composer 安装命令:
composer require patrikjak/auth
包简介
Simple auth package for laravel apps
README 文档
README
Simple auth package for Laravel apps. Requires patrikjak/utils.
Installation
composer require patrikjak/auth
Setup
Register both service providers in bootstrap/providers.php:
use Patrikjak\Auth\AuthServiceProvider; use Patrikjak\Utils\UtilsServiceProvider; return [ // ... UtilsServiceProvider::class, AuthServiceProvider::class, ];
Run the install command to publish all assets, config, migrations, and translations, remove default Laravel auth migrations, run fresh migrations, and seed default roles:
php artisan install:pjauth
Or publish individually:
php artisan vendor:publish --tag="pjauth-assets" --force php artisan vendor:publish --tag="pjauth-config" php artisan vendor:publish --tag="pjauth-migrations" --force php artisan vendor:publish --tag="pjauth-translations" --force php artisan vendor:publish --tag="pjauth-views" --force # optional
To keep config up to date on every composer update, add to your composer.json:
"scripts": { "post-update-cmd": [ "@php artisan vendor:publish --tag=pjauth-config --force" ] }
Laravel cannot merge multidimensional arrays in config files, so the config must be re-published after updates.
Configuration
All options live in config/pjauth.php.
Custom User model
AUTH_MODEL=App\Models\User
Default is Patrikjak\Auth\Models\User.
Custom repository
// config/pjauth.php 'repositories' => [ 'user' => \App\Repositories\UserRepository::class, ],
The custom implementation must implement Patrikjak\Auth\Repositories\Interfaces\UserRepository.
Redirects
'redirect_after_login' => env('REDIRECT_AFTER_LOGIN', '/dashboard'), 'redirect_after_logout' => env('REDIRECT_AFTER_LOGOUT', '/'),
Feature flags
All features are enabled by default except register_via_invitation:
'features' => [ 'register' => true, 'login' => true, 'password_reset' => true, 'change_password' => true, 'register_via_invitation' => false, ],
Routes are only registered when their respective feature is enabled.
Routes
Web routes use ['web', 'guest'] middleware. API routes use ['web', 'guest'] for unauthenticated endpoints and ['web', 'auth'] for authenticated ones.
Middleware
Use VerifyRole to protect routes by role:
use Patrikjak\Auth\Http\Middlewares\VerifyRole; Route::middleware(['web', 'auth', VerifyRole::withRole('admin')]);
Super admins pass all role checks.
Roles
Default roles are defined in config/pjauth.php under default_roles. Use pjauth:sync-roles to seed them — see Artisan Commands.
Artisan Commands
Sync roles
php artisan pjauth:sync-roles
Seeds roles from pjauth.default_roles config into the database (uses firstOrCreate — safe to re-run).
Create users interactively
php artisan pjauth:create-users
Prompts for name, email, password, and role. Loops until you decline to add another user.
Send register invite
php artisan pjauth:send-invite user@example.com # or pass a role ID directly: php artisan pjauth:send-invite user@example.com --role=<role-id>
If --role is not provided, available roles are listed and you are prompted to choose.
Socialite (Google)
Enable in config (enabled by default) and add credentials:
GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET=
Add to config/services.php:
'google' => [ 'client_id' => env('GOOGLE_CLIENT_ID'), 'client_secret' => env('GOOGLE_CLIENT_SECRET'), 'redirect' => sprintf('%s/auth/google/callback', env('APP_URL')), ],
Register via Invitation
Enable the feature flag:
'features' => [ 'register_via_invitation' => true, ],
When enabled, the invitation routes are registered. Google social login on the login screen remains available so existing users can still sign in via Google — only the "sign up with Google" button on the register screen is hidden, and Google OAuth cannot be used to create a new account.
Send an invite from the command line — see Artisan Commands.
The invite email contains a tokenised link to GET /register/{token}?email=.... On submission it calls POST /api/invite/register.
Change Password
Enable the feature flag (enabled by default):
'features' => [ 'change_password' => true, ],
Call the authenticated endpoint:
PATCH api/change-password
Request body:
{
"current_password": "current_password",
"password": "new_password",
"password_confirmation": "new_password"
}
Old password validation is on by default. To skip it (e.g. admin resetting another user's password):
{
"password": "new_password",
"password_confirmation": "new_password",
"validate_current_password": false
}
reCAPTCHA
Enabled by default on register, login, and password reset API endpoints. Disable globally:
'recaptcha' => [ 'enabled' => false, ],
Or provide the keys:
RECAPTCHA_SITE_KEY= RECAPTCHA_SECRET_KEY=
patrikjak/auth 适用场景与选型建议
patrikjak/auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 740 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「auth」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 patrikjak/auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 patrikjak/auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 patrikjak/auth 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Multiauth package
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
This package provides a flexible way to add Role-based Permissions to Laravel 6.x
Email Toolkit Plugin for CakePHP
Alfabank REST API integration
:Small library PHP for authentication support facebook, google, key, jwt, diggest, basic and session
统计信息
- 总下载量: 740
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-26