承接 equidna/swift-auth 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

equidna/swift-auth

最新稳定版本:4.0.0

Composer 安装命令:

composer require equidna/swift-auth

包简介

Bottled authentication for Laravel projects

README 文档

README

Bottled authentication for Laravel projects.

SwiftAuth is a production-ready authentication package for Laravel 11 and 12 that provides a complete, drop-in identity management layer. It ships session-based authentication, multi-factor authentication (OTP and WebAuthn / Passkeys), role-based access control, concurrent session management with configurable limits and eviction strategies, account lockout, password reset, email verification, remember-me tokens, API token issuance (Sanctum-compatible), and multi-tenancy via BeeHive — all configurable through a single published config file and accessible through a clean Facade.

Package type: Composer library (not a standalone application). Namespace: Equidna\SwiftAuth\. Service provider: Equidna\SwiftAuth\Providers\SwiftAuthServiceProvider (auto-discovered via composer.json).

Documentation Index

This documentation and the codebase follow the project's Coding Standards Guide and PHPDoc Style Guide.

Tech Stack & Requirements

Property Value
Type Laravel Package (Composer library)
PHP ^8.2, ^8.3, ^8.4
Laravel 11.x / 12.x
Frontend Blade, Inertia + TypeScript, or Inertia + JavaScript
Database Any Laravel-supported driver (SQLite, MySQL, PostgreSQL)
Cache Any Laravel cache driver
Queue Not required (operations are synchronous by default)

Key dependencies:

  • equidna/bee-hive ^2.0 — Multi-tenancy (BelongsToTenant trait, TenantScope, TenantContext)
  • equidna/bird-flock ^1.2 — Notification and email dispatch bus
  • equidna/toolkit — Shared helpers: ResponseHelper, exceptions
  • laragear/webauthn ^5.0 — WebAuthn / Passkey support
  • laravel/sanctum ^4.3 — API token authentication
  • inertiajs/inertia-laravel ^3.0 — Inertia.js SPA adapter

Quick Start

  1. Install the package:

    composer require equidna/swift-auth
  2. Run the install command (publishes config, runs migrations):

    php artisan swift-auth:install
  3. Configure environment variables in .env:

    SWIFT_AUTH_FRONTEND=typescript          # blade | typescript | javascript
    SWIFT_AUTH_SUCCESS_URL=/dashboard
    SWIFT_AUTH_ALLOW_REGISTRATION=false
    SWIFT_AUTH_TABLE_PREFIX=swift-auth_
    SWIFT_AUTH_ROUTE_PREFIX=swift-auth
  4. Run migrations (if not already run by the installer):

    php artisan migrate
  5. Create an initial admin user:

    php artisan swift-auth:create-admin
  6. Start the application:

    php artisan serve

    Navigate to /{route-prefix}/login (default: /swift-auth/login).

Using the Facade

use Equidna\SwiftAuth\Support\Facades\SwiftAuth;

// Check authentication
if (SwiftAuth::check()) {
    $user = SwiftAuth::user();
    $userId = SwiftAuth::id();
}

// Permission checks
SwiftAuth::canPerformAction('sw-admin');
SwiftAuth::hasRole('administrator');

// Session management
$sessions = SwiftAuth::sessionsForUser($userId);
SwiftAuth::revokeSession($userId, $sessionId);

// Manual login/logout
SwiftAuth::login($user, $ip, $userAgent, $deviceName, remember: true);
SwiftAuth::logout();

Protecting Routes

Session-based (web) authentication:

Route::middleware('SwiftAuth.RequireAuthentication')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
});

// With action-based authorization
Route::middleware(['SwiftAuth.RequireAuthentication', 'SwiftAuth.CanPerformAction:sw-admin'])
    ->group(function () {
        Route::get('/admin', [AdminController::class, 'index']);
    });

API token authentication:

Route::middleware('SwiftAuth.AuthenticateWithToken')->group(function () {
    Route::get('/api/profile', [ProfileController::class, 'show']);
});

// With token ability check
Route::middleware(['SwiftAuth.AuthenticateWithToken', 'SwiftAuth.CheckTokenAbilities:posts:write'])
    ->group(function () {
        Route::post('/api/posts', [PostController::class, 'store']);
    });

For full reference, see Securing Routes.

Localization

SwiftAuth ships translations for English (en) and Spanish (es). Locale is persisted in the user session and can be switched at runtime via the POST /{prefix}/locale/{locale} endpoint.

In PHP / Blade:

__('swift-auth::auth.login_title')

In TypeScript / JavaScript:

import { __ } from "../../../lang/translations";
<h1>{__("auth.login_title")}</h1>

For comprehensive localization documentation, see Localization Guide.

统计信息

  • 总下载量: 31
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固