定制 cetria/laravel-auth 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

cetria/laravel-auth

最新稳定版本:1.0.0

Composer 安装命令:

composer require cetria/laravel-auth

包简介

Laravel package providing customizable authentication API endpoints using Sanctum and Bearer tokens.

README 文档

README

Custom Laravel package providing ready-to-use authentication API endpoints using Sanctum and Bearer tokens.

Features

  • Plug-and-play authentication routes
  • Login with token creation (/auth)
  • Get current user (/me)
  • Logout current device (/logout)
  • Logout all devices (/allDeviceLogout)
  • Custom guard with named tokens (e.g. devel, mobile, etc.)

Installation

composer require cetria/cetria-laravel-auth

Configuration

  1. Register the service provider (if not auto-discovered). If your Laravel version does not support package auto-discovery or you have it disabled, manually register the service provider in bootstrap/providers.php:
    Cetria\Laravel\Auth\Providers\SanctumWithSpecialTokenNames::class,
    
  2. Add the custom guard to config/auth.php:
    'guards' => [
     'sanctumWithSpecialTokenNames' => [
         'driver' => 'sanctumWithSpecialTokenNames',
         'provider' => 'users',
     ],
    ],
    

Usage

Define routes in routes\api.php:

use Illuminate\Support\Facades\Route;
use Cetria\Laravel\Auth\Providers\SanctumWithSpecialTokenNames;

Route::post('/auth', [Auth::class, 'auth'])->name('auth');

// Protected routes
Route::middleware('auth:' . SanctumWithSpecialTokenNames::$guardName)->group(function () {
    Route::get('/me', [Auth::class, 'me']);
    Route::get('/logout', [Auth::class, 'logout']);
    Route::get('/allDeviceLogout', [Auth::class, 'logoutAllDevices']);

    // Add more authenticated routes here...
});

Testing

This package includes pre-built feature tests for the authentication endpoints and the custom guard.

Requirements

To run the tests, make sure the following dependencies are installed:

  • phpunit >= 11.0
  • cetria/reflection >= 0.2

Auth User Model

Your user model must:

  • implements Cetria\Laravel\Auth\Interfaces\AuthUser
  • Use the Illuminate\Database\Eloquent\Factories\HasFactory trait

Auth User Factory

Your factory class must:

  • implements the Cetria\Laravel\Auth\Interfaces\AuthModelFactory
  • Use the Cetria\Laravel\Auth\Traits\AuthModelFactory trait

Setup

Once the requirements are met, add the test directory to your phpunit.xml configuration:

<testsuites>
  <testsuite name="FeatureAuth">
    <directory>vendor/cetria/laravel-auth/src/Tests/Feature</directory>
  </testsuite>
</testsuites>

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-12