Skip to main content

Posts

Showing posts with the label OAuth2

Laravel Authentication: Sanctum vs Passport

Laravel Authentication: Sanctum vs Passport (with Examples) Laravel offers two main authentication packages: Sanctum and Passport . Both solve different problems — Sanctum is lightweight and best for SPAs and mobile apps, while Passport is a full OAuth2 server solution. Let’s break it down with examples and comparisons. 1. Quick Comparison Feature Sanctum Passport Use case First-party SPA & simple API tokens Full OAuth2 server with scopes, grants Complexity Simple, easy to setup Advanced, more config needed Token type Personal access tokens, SPA cookies Access + Refresh tokens Best for Single backend apps, mobile APIs Third-party integrations, OAuth2 2. Sanctum Setup Example Sanctum is great for issuing API tokens and handling SPA cookie-based auth. Here’s how to set i...