rockstoneaidev/auth-bridge-laravel
Composer 安装命令:
composer require rockstoneaidev/auth-bridge-laravel
包简介
Bridge package for Laravel applications to authenticate against the centralized Auth API service.
README 文档
README
rockstoneaidev/auth-bridge-laravel is a reusable bridge package for Laravel applications that authenticate and authorize via Firebase Authentication (recommended) or the centralized Auth API service (legacy).
It keeps a lightweight local user record in sync with the external identity provider while delegating all token handling, roles, and permissions to the configured provider.
Requirements
- PHP 8.4+
- Laravel 12.x
- Firebase Project (for Firebase provider) OR Central Auth API v1 (for Auth API provider)
Installation
composer require rockstoneaidev/auth-bridge-laravel
Publish the configuration (optional) and migrations, then migrate:
php artisan vendor:publish --tag=auth-bridge-config php artisan vendor:publish --tag=auth-bridge-migrations php artisan migrate
Publishing the migration adds the shared external_* columns (and avatar_url / last_seen_at) to your app's users table. These columns serve as the local cache of the remote identity (Firebase UID or Auth API UUID).
Configuration
1. Select Provider
Update .env to select your authentication provider:
# Options: firebase (default/recommended) | auth_api (legacy) AUTH_BRIDGE_PROVIDER=firebase
2. Configure Provider
Option A: Firebase (Default)
Configure your Firebase project details. Use a separate Firebase project for each environment (e.g., myapp-staging, myapp-prod).
FIREBASE_PROJECT_ID=my-app-staging # Optional: Override defaults # FIREBASE_JWKS_URL=... # FIREBASE_ISSUER_PREFIX=...
The bridge verifies Firebase ID tokens (JWT) using Google's public keys and maps claims to your local users table.
Option B: Auth API (Legacy)
For apps using the existing centralized Auth API infrastructure:
AUTH_BRIDGE_PROVIDER=auth_api AUTH_BRIDGE_BASE_URL=https://auth.example.com/api/v1 AUTH_BRIDGE_PUBLIC_URL=https://auth.example.com
Configure the Guard
Update config/auth.php with a bridge guard that uses your existing users provider:
'guards' => [ 'api' => [ 'driver' => 'auth-bridge', 'provider' => 'users', 'cache_ttl' => 30, // seconds (set 0 to disable caching) ], ],
Point any API routes that rely on remote tokens to this guard:
Route::middleware(['auth:api'])->group(function () { Route::get('/me', fn () => request()->user()); });
The guard automatically:
- Extracts the Bearer token.
- Authenticates via the configured provider (Firebase or Auth API).
- Synchronizes the identity to your local
userstable. - Injects the hydrated local user into the request (
request()->user())
User Model Setup
Add the provided trait to your App\Models\User:
use AuthBridge\Laravel\Concerns\HasAuthBridgeUser; class User extends Authenticatable { use HasAuthBridgeUser; }
Onboarding a New App
With Firebase (Recommended)
- Create a Firebase project at Firebase Console.
- Enable Authentication (Email/Password, Google, etc.).
- Set
AUTH_BRIDGE_PROVIDER=firebaseandFIREBASE_PROJECT_ID=...in.env. - Use the Firebase JS SDK in your frontend to obtain an ID token.
- Send the token as
Authorization: Bearer <token>to your Laravel API.
With Auth API (Legacy)
Run the onboarding command to register your app and scaffold the OAuth client:
php artisan auth-bridge:onboard \ --app-key=docs \ --app-name="Docs" \ --redirect=${APP_URL}/oauth/callback \ --bootstrap-token=${AUTH_API_BOOTSTRAP_TOKEN}
Accessing Remote Context
Use the facade or injected AuthBridgeContext service to read the raw payload or check permissions:
use AuthBridge\Laravel\Facades\AuthBridge; if (AuthBridge::hasPermission('documents.write')) { // user has permission }
Contributing
Issues and PRs are welcome. Please run composer test (Pest via Testbench) before opening a PR.
rockstoneaidev/auth-bridge-laravel 适用场景与选型建议
rockstoneaidev/auth-bridge-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 98 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Authentication」 「oauth2」 「SSO」 「laravel」 「auth-bridge」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rockstoneaidev/auth-bridge-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rockstoneaidev/auth-bridge-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rockstoneaidev/auth-bridge-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
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.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
Email Toolkit Plugin for CakePHP
The missing social authentication for thephpleague/oauth2-server, adapted from schedula/league-oauth2-social
统计信息
- 总下载量: 98
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-28