bibrokhim/auth-gateway
Laravel auth gateway package providing a simple authentication layer for APIs/apps, with easy integration into existing projects. Helps centralize login/token handling and protect routes via middleware/guards.
Auth::attempt()) or as a standalone layer.AuthGateway, TokenManager) that could conflict with Laravel’s native Auth facade.Auth::gateway()->authorize()).HasApiTokens (for Sanctum) or Passport.users, tokens, roles, permissions (may overlap with Laravel’s users table).users table for auth-gateway-specific fields.Auth::user()) or is this a backend-for-frontend (BFF) auth layer?users table or require a separate DB schema?Auth::attempt()) interact with AuthGateway?Auth::login(), JWT::fromUser()).AuthGateway equivalents.auth:api → auth-gateway:jwt).// Replace Laravel's Sanctum token logic
use Bibrokhim\AuthGateway\Facades\AuthGateway;
AuthGateway::token()->generateForUser($user);
Auth::user() with AuthGateway::user() in APIs.AuthGateway::provider().Auth::attempt()).composer.json for supported Laravel versions (likely 8.x–10.x).auth:api with auth-gateway:jwt or auth-gateway:oauth.Route::middleware(['auth-gateway:jwt'])->group(function () {
// Protected routes
});
AuthGatewayServiceProvider in config/app.php.php artisan vendor:publish --provider="Bibrokhim\AuthGateway\AuthGatewayServiceProvider"
AuthGateway in PHPUnit tests to avoid DB dependencies.$this->mock(AuthGateway::class)->shouldReceive('user')->andReturn($user);
composer require bibrokhim/auth-gateway
.env:
AUTH_GATEWAY_DEFAULT=jwt
AUTH_GATEWAY_JWT_SECRET=your-secret
app/Providers/AuthServiceProvider.php to bind AuthGateway./api/auth-gateway/login).AuthGateway calls for easier replacement.dd($authGateway->getUser()))..env:
AUTH_GATEWAY_DEBUG=true
AuthGatewayException) may not integrate with Laravel’s error handlers.try {
AuthGateway::authorize('admin');
} catch (AuthorizationException $e) {
abort(403, $e->getMessage());
}
event(new AuthGateway\Events\LoginAttempt($user, $success));
How can I help you explore Laravel packages today?