agentsclimarketplace

Laravel auth

Skill fusengine/agents/plugins/laravel-expert/skills/laravel-auth

Redefining development through cognitive automation and collaborative agent systems.

Install
npx -y skills add fusengine/agents --skill laravel-auth

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 22 stars22 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when implementing user authentication, API tokens, social login, or authorization in Laravel 13.

SKILL.md

10.2 KB, as published. Nobody here has run it

<objective> Covers the Laravel 13 authentication and authorization ecosystem: Sanctum (API tokens, SPA auth), Passport (OAuth2 server), Fortify (headless custom-UI auth), Socialite (social login), starter kits, policies and gates, email verification, password reset, session management, CSRF / PreventRequestForgery, encryption, and hashing. Includes FuseCore modular- project integration patterns for auth (User module, cross-module authorization via policies). </objective>

Laravel Authentication & Authorization

Agent Workflow (MANDATORY)

Before ANY implementation, use TeamCreate to spawn 3 agents:

  1. fuse-ai-pilot:explore-codebase - Check existing auth setup, guards, policies
  2. fuse-ai-pilot:research-expert - Verify latest Laravel 13 auth docs via Context7
  3. mcp__context7__query-docs - Query specific patterns (Sanctum, Passport, etc.)

After implementation, run fuse-ai-pilot:sniper for validation.


Overview

Laravel provides a complete authentication and authorization ecosystem. Choose based on your needs:

PackageBest ForComplexity
Starter KitsNew projects, quick setupLow
SanctumAPI tokens, SPA authLow
FortifyCustom UI, headless backendMedium
PassportOAuth2 server, third-party accessHigh
SocialiteSocial login (Google, GitHub)Low

Critical Rules

  1. Use policies for model authorization - Not inline if checks
  2. Always hash passwords - Hash::make() or 'hashed' cast
  3. Regenerate session after login - Prevents fixation attacks
  4. Use HTTPS in production - Required for secure cookies
  5. Define token abilities - Principle of least privilege

Architecture

app/
├── Http/
│   ├── Controllers/
│   │   └── Auth/              ← Auth controllers (if manual)
│   └── Middleware/
│       └── Authenticate.php   ← Redirects unauthenticated
├── Models/
│   └── User.php               ← HasApiTokens trait (Sanctum)
├── Policies/                  ← Authorization policies
│   └── PostPolicy.php
├── Providers/
│   └── AppServiceProvider.php ← Gate definitions
└── Actions/
    └── Fortify/               ← Fortify actions (if used)
        ├── CreateNewUser.php
        └── ResetUserPassword.php

config/
├── auth.php                   ← Guards & providers
├── sanctum.php                ← API token config
└── fortify.php                ← Fortify features

FuseCore Integration

When working in a FuseCore project, authentication follows the modular structure:

FuseCore/
├── Core/                      # Infrastructure (priority 0)
│   └── App/Contracts/
│       └── AuthServiceInterface.php  ← Auth contract
│
├── User/                      # Auth module (existing)
│   ├── App/
│   │   ├── Models/User.php    ← HasApiTokens trait
│   │   ├── Http/
│   │   │   ├── Controllers/
│   │   │   │   ├── AuthController.php
│   │   │   │   └── TokenController.php
│   │   │   ├── Requests/
│   │   │   │   ├── LoginRequest.php
│   │   │   │   └── RegisterRequest.php
│   │   │   └── Resources/UserResource.php
│   │   ├── Policies/UserPolicy.php
│   │   └── Services/AuthService.php
│   ├── Config/
│   │   └── sanctum.php        ← Sanctum config (module-level)
│   ├── Database/Migrations/
│   ├── Routes/api.php         ← Auth routes
│   └── module.json            # dependencies: []
│
└── {YourModule}/              # Depends on User module
    ├── App/Policies/          ← Module-specific policies
    └── module.json            # dependencies: ["User"]

FuseCore Auth Checklist

  • Auth code in /FuseCore/User/ module
  • Policies in module's /App/Policies/
  • Auth routes in /FuseCore/User/Routes/api.php
  • Sanctum config in /FuseCore/User/Config/sanctum.php
  • Declare "User" dependency in other modules' module.json
  • Use auth:sanctum middleware in module routes

Cross-Module Authorization

// In FuseCore/{Module}/Routes/api.php
Route::middleware(['api', 'auth:sanctum'])->group(function () {
    Route::apiResource('posts', PostController::class);
});

// In FuseCore/{Module}/App/Http/Controllers/PostController.php
public function update(UpdatePostRequest $request, Post $post)
{
    $this->authorize('update', $post);  // Uses PostPolicy
    // ...
}

→ See fusecore skill for complete module patterns.


Decision Guide

Authentication Method

Need auth scaffolding? → Starter Kit
├── Yes → Use React/Vue/Livewire starter kit
└── No → Building custom frontend?
    ├── Yes → Use Fortify (headless)
    └── No → API only?
        ├── Yes → Sanctum (tokens)
        └── No → Session-based

Token Type

Third-party apps need access? → Passport (OAuth2)
├── No → Mobile app?
│   ├── Yes → Sanctum API tokens
│   └── No → SPA on same domain?
│       ├── Yes → Sanctum SPA auth (cookies)
│       └── No → Sanctum API tokens

Key Concepts

ConceptDescriptionReference
GuardsDefine HOW users authenticate (session, token)authentication.md
ProvidersDefine WHERE users are retrieved from (database)authentication.md
GatesClosure-based authorization for simple checksauthorization.md
PoliciesClass-based authorization tied to modelsauthorization.md
AbilitiesToken permissions (Sanctum/Passport scopes)sanctum.md

Reference Guide

Concepts (WHY & Architecture)

TopicReferenceWhen to Consult
Authenticationauthentication.mdGuards, providers, login flow
Authorizationauthorization.mdGates vs policies, access control
Sanctumsanctum.mdAPI tokens, SPA authentication
Passportpassport.mdOAuth2 server, third-party access
Fortifyfortify.mdHeadless auth, 2FA
Socialitesocialite.mdSocial login providers
Starter Kitsstarter-kits.mdAuth scaffolding
Email Verificationverification.mdMustVerifyEmail, verified middleware
Password Resetpasswords.mdForgot password flow
Sessionsession.mdSession drivers, flash data
CSRFcsrf.mdForm protection, AJAX tokens
Encryptionencryption.mdData encryption (not passwords)
Hashinghashing.mdPassword hashing

Templates (Complete Code)

TemplateWhen to Use
LoginController.php.mdManual authentication controllers
GatesAndPolicies.php.mdGates and policy examples
PostPolicy.php.mdComplete policy class with before filter
sanctum-setup.mdSanctum configuration + testing
PassportSetup.php.mdOAuth2 server setup
FortifySetup.php.mdFortify configuration + 2FA
SocialiteController.php.mdSocial login + testing
PasswordResetController.php.mdPassword reset flow

Best Practices

DO

  • Use starter kits for new projects
  • Define policies for all models
  • Set token expiration
  • Rate limit login attempts
  • Use verified middleware for sensitive actions
  • Prune expired tokens regularly

DON'T

  • Store plain text passwords
  • Skip session regeneration on login
  • Use Passport when Sanctum suffices
  • Forget to prune expired tokens
  • Ignore HTTPS in production
  • Put authorization logic in controllers

Laravel 13 Notes

PreventRequestForgery (ex-VerifyCsrfToken)

Laravel 13 renomme VerifyCsrfToken en PreventRequestForgery. Le middleware utilise une vérification origin-aware (vérifie Origin/Referer en plus du token CSRF) pour bloquer les attaques CSRF cross-origin sur les routes stateful.

// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->validateOrigin(except: ['stripe/*', 'webhook/*']);
})
  • Migrer toute référence VerifyCsrfToken::classPreventRequestForgery::class
  • Property $except reste compatible mais préférer validateOrigin(except: [...])
  • Les APIs stateless (Sanctum tokens) ne sont pas affectées

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.