Laravel Sanctum vs Passport — Which API Auth Should You Use?
Laravel Sanctum is the lighter choice for SPAs and simple API tokens; Passport is full OAuth2 for third-party apps. Pick Sanctum for most apps, Passport when you need real OAuth2.

Quick Answer
Laravel Sanctum is a lightweight auth package for SPAs, mobile apps, and simple API tokens. Laravel Passport is a full OAuth2 server for third-party client authorization. Use Sanctum for most first-party apps; use Passport when you need real OAuth2 scopes, clients, and third-party access.
Quick Facts
Topic: Laravel Sanctum vs Passport
Category: Laravel / API Authentication
Table of Contents
- What Is Laravel Sanctum vs Passport?
- Why It Matters
- How It Works
- Step-by-Step Guide
- Real Example
- Pros & Cons
- Best Practices
- Common Mistakes
- FAQs
- Key Takeaways
What Is Laravel Sanctum vs Passport?
Laravel Sanctum and Laravel Passport are official packages for API authentication, but they solve different problems.
Sanctum issues personal access tokens and supports cookie-based SPA authentication for same-domain (or configured) frontends. It is simple, token-based, and first-party focused.
Passport implements the full OAuth2 authorization server. It manages clients, authorization codes, refresh tokens, and scopes — the pattern apps like Google or GitHub use when other apps request access on a user’s behalf.
Why It Matters
- Right tool, less complexity — Passport adds OAuth2 machinery you may never need.
- Security posture — SPA cookie auth, mobile tokens, and third-party clients each need a different model.
- Maintenance cost — Sanctum is easier to reason about; Passport needs client management and stricter scope design.
- Product direction — Internal SPA vs public API platform changes the correct choice immediately.
How It Works
- Sanctum (SPA) — The frontend logs in via session/cookie. CSRF protection + authenticated requests use the same domain cookies.
- Sanctum (token) — The API creates a personal access token; the client sends
Authorization: Bearer <token>. - Passport (OAuth2) — A client app requests authorization. Passport issues access (and often refresh) tokens with scopes after the user consents.
- Authorization checks — Both protect routes with Laravel’s auth middleware; Passport adds OAuth scopes and client trust boundaries.
Step-by-Step Guide
Step 1: Choose based on product needs
Ask three questions: Is the client first-party only? Do you need third-party apps to act for users? Do you need OAuth2 grant types and scopes?
- First-party SPA / mobile / simple tokens → Sanctum
- Third-party developers, OAuth clients, authorization code flow → Passport
Step 2: Install and configure the package
For Sanctum:
composer require laravel/sanctum
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
php artisan migrate
For Passport:
composer require laravel/passport
php artisan migrate
php artisan passport:install
Then wire the User model traits (HasApiTokens), auth guards, and CORS/SPA cookie settings as needed.
Step 3: Protect routes and test auth flows
Use auth:sanctum or Passport’s API guard on protected routes. Test login, token issue/revoke, expired tokens, and (for Passport) client creation + scope-limited requests before shipping.
Real-World Example
Scenario A — SaaS dashboard + mobile app (first-party): Your Vue/Nuxt admin and mobile app talk only to your Laravel API. Users authenticate with you, not via other apps. Sanctum SPA cookies for the web app and personal access tokens for mobile is enough — no OAuth2 server overhead.
Scenario B — Public developer platform: Other companies’ apps need “Login with YourApp” and limited access to user data. That is Passport territory: OAuth clients, consent screens, scopes like read:profile, and refresh tokens.
Pros & Cons
Advantages
- Sanctum: Lightweight setup, great for SPAs and simple tokens, less conceptual overhead.
- Sanctum: Fits first-party web + mobile patterns cleanly.
- Passport: Full OAuth2 compliance for third-party integrations.
- Passport: Built-in clients, scopes, and common OAuth grant flows.
Disadvantages
- Sanctum: Not a full OAuth2 server — weak fit for public third-party API ecosystems.
- Passport: Heavier install, more moving parts (keys, clients, grants).
- Passport: Overkill for single SPA or internal APIs — more to secure and maintain.
Best Practices
- Default to Sanctum unless you clearly need OAuth2.
- For Sanctum SPAs, configure stateful domains, CSRF, and CORS carefully — cookie auth fails silently when domains mismatch.
- Store API tokens securely (never in localStorage for high-risk apps if you can use httpOnly cookies for web).
- With Passport, design scopes narrowly — avoid a single “full access” scope for every client.
- Always support token revocation and rotate secrets after incidents.
- Document which guard protects which route group so frontend and mobile teams don’t mix flows.
Common Mistakes
- Choosing Passport by default → Fix: start with Sanctum for first-party apps; upgrade only if OAuth2 is required.
- Using Sanctum like OAuth for third parties → Fix: personal access tokens are not a substitute for consent + client isolation; use Passport.
- Broken SPA cookies due to CORS/domain misconfig → Fix: align
SANCTUM_STATEFUL_DOMAINS,SESSION_DOMAIN, and frontend origin. - Never expiring or revoking tokens → Fix: set TTLs, revoke on logout/password change, audit long-lived tokens.
- Mixing guards without clear route groups → Fix: separate web/SPA and API token routes with explicit middleware.
Frequently Asked Questions
What is Laravel Sanctum vs Passport?
Sanctum is lightweight API/SPA authentication for first-party apps. Passport is Laravel’s full OAuth2 server for authorizing third-party clients with scopes and grant types.
How do I choose between Sanctum and Passport?
If only your own frontend or mobile app authenticates users, choose Sanctum. If external apps need user-authorized access to your API, choose Passport.
Sanctum vs Passport for a Vue or Nuxt SPA?
Use Sanctum. Cookie-based SPA auth (or token auth if preferred) is the documented first-party pattern. Passport adds unnecessary OAuth complexity for same-product SPAs.
Is Laravel Passport still worth it in 2026?
Yes — when you need OAuth2. For most CRUD APIs and first-party SPAs, Sanctum is still the better default. Passport remains the right pick for public API platforms and “Login with …” style products.
Can I use Sanctum and Passport together?
Possible but rarely worth it. Pick one primary model for clarity. Running both increases guard/config confusion unless you have a clear split (e.g., first-party vs third-party route groups).
Summary
Laravel Sanctum vs Passport is mainly a product decision, not a popularity contest. Sanctum wins for first-party SPAs, mobile apps, and simple personal access tokens. Passport wins when you must be an OAuth2 provider.
If you are building a normal Laravel API with your own frontend, start with Sanctum. Move to Passport only when third-party clients, consent, and scopes become real product requirements.
Next step: map your clients (SPA, mobile, external apps). If every client is yours, install Sanctum and ship. If others must authorize against you, plan Passport clients and scopes first.
Key Takeaways
- Sanctum = lightweight first-party API/SPA auth; Passport = full OAuth2 server.
- Most Laravel apps should start with Sanctum.
- Choose Passport for third-party apps, scopes, and OAuth grant flows.
- Cookie domain/CORS mistakes cause most Sanctum SPA auth failures.
- Decision rule: first-party only → Sanctum; public OAuth platform → Passport.
Comments
0 comments · new ones appear after approval
No comments yet. Be the first to share your thoughts.
Leave a comment
Your comment will be reviewed before it appears.