laravel/sanctum

Authentication and authorisation

Issues API tokens (personal access tokens) and authenticates single page apps with Laravel's cookie sessions, without the weight of OAuth.

The problem it solves

Small APIs and first-party SPAs need authentication, but OAuth is more than they need.

Install

composer require laravel/sanctum

Example

From the Laravel docs: add the HasApiTokens trait to the User model, then issue a token.

use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;
}

Route::post('/tokens/create', function (Request $request) {
    $token = $request->user()->createToken($request->token_name);

    return ['token' => $token->plainTextToken];
});

Requirements and activity

Fetched from Packagist and GitHub on 2026-11-29. Constraints show what the package allows, not what its maintainers tested.

Latest stablev4.5.0 (2026-11-11)
PHP^8.2
Laravel^12.0|^13.0
LicenseMIT
Downloads (Packagist, total)248,983,297
GitHub stars2,988
Last push2026-11-17
StatusNot marked abandoned

Strengths

  • Two separate features: API tokens, and cookie-session authentication for SPAs. You can use either one alone.
  • Tokens are hashed with SHA-256 before storage.
  • Installed with php artisan install:api.

Limits to know

  • The docs say not to use API tokens to authenticate your own first-party SPA; use the SPA cookie authentication instead.
  • SPA authentication relies on CSRF and cookie setup, which is where the related 419 questions come from.

Related questions

Official links

Documentation · Packagist · GitHub

Write-up based on: laravel.com/docs/12.x/sanctum. Written from the official README and docs; not tested by Laravel Questions. All packages.

Our network