Skip to main content

What is Passport

Laravel Passport is the official package for running a Laravel application as an OAuth2 authorization server. Use it for third-party app integrations and APIs that require a strict OAuth2 flow.

Passport vs Sanctum

Choose Passport if OAuth2 is required. Choose Sanctum for simple API token authentication or SPA / mobile authentication.

Installation

The official recommendation in Laravel 13 is install:api --passport.
For a manual installation on an existing project, you can also set it up with the following commands.
There are cases where you only want to generate keys on the initial deployment.

Configuration

User model

Add the HasApiTokens trait and the OAuthenticatable interface to your User model.

auth guard

In the api guard of config/auth.php, use the passport driver.

Service provider configuration

In your AppServiceProvider’s boot() method, you can define scopes and token expirations.

Client management

Authorization code grant client

This client is used with the standard OAuth2 flow that involves a user consent screen.

Client credentials grant client

For machine-to-machine endpoints, use the EnsureClientIsResourceOwner middleware.

Token management

Granting scopes

Checking scopes

Revocation

Protecting API routes

Attach auth:api to APIs protected by user access tokens.
For client credentials grant routes, use EnsureClientIsResourceOwner instead of auth:api.

Personal Access Tokens

These are well-suited to cases where the user themselves issues an API token without going through the full OAuth2 flow.
If Personal Access Tokens are your primary use case, Laravel itself officially recommends considering Sanctum.
Last modified on July 13, 2026