Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Passport Laravel Package

laravel/passport

Laravel Passport provides a full OAuth2 server for Laravel, enabling API authentication with access tokens, personal access tokens, and client credentials. Includes token issuing, revocation, and scope support with first-party integration.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

Laravel Passport is a first-class OAuth2 server implementation for Laravel, designed to integrate seamlessly with the framework’s ecosystem. It aligns well with:

  • Microservices/API-first architectures (e.g., headless APIs, SPAs, mobile backends).
  • Legacy system modernization (replacing custom auth with standardized OAuth2).
  • Multi-tenant SaaS (scoped tokens, client isolation).
  • API gateways (acting as an auth layer for downstream services).

Key strengths:

  • Laravel-native: Leverages Eloquent, migrations, and service providers.
  • OAuth2 compliance: Supports all core grants (Authorization Code, Client Credentials, Password, Refresh Token, Device Code).
  • Extensibility: Custom scopes, middleware, and token logic via hooks.
  • Headless support: Works with Laravel Jetstream/Breeze without UI dependencies.

Anti-patterns:

  • Avoid for monolithic apps with tightly coupled auth (e.g., session-based Laravel apps where OAuth2 adds unnecessary complexity).
  • Not ideal for highly dynamic auth flows (e.g., real-time systems requiring WebSockets + OAuth2; consider alternatives like Laravel Sanctum for simpler cases).

Integration Feasibility

Factor Feasibility Notes
Laravel Version High Supports Laravel 10+ (v13.x); backward-compatible with 9.x via older versions.
Database High Uses standard oauth_* tables (MySQL, PostgreSQL, SQLite). Customizable via migrations.
Existing Auth Medium-High Requires OAuthenticatable interface on user models; may need guard/config adjustments.
Third-Party APIs High Acts as an OAuth2 provider for external clients (e.g., React Native, Postman, or other APIs).
Performance High Optimized for token generation/revocation; supports caching (e.g., Redis for token storage).
Security High Built-in CSRF, PKCE, and token revocation; MITM-resistant with HTTPS.

Critical Dependencies:

  • league/oauth2-server (v9.x): Core OAuth2 logic.
  • firebase/php-jwt: JWT token handling (v7.x+).
  • Laravel’s auth and hash components.

Potential Conflicts:

  • Token Storage: Defaults to DB; may need Redis for scalability.
  • User Model: Requires findForPassport() method (customizable but adds boilerplate).
  • Middleware: Passport::routes() must be called in AuthServiceProvider.

Technical Risk

Risk Area Severity Mitigation
Migration Complexity Medium Schema changes (e.g., UUIDs for clients in v13) may require downtime. Use Passport::hash() and test thoroughly.
Token Leakage High Client secrets must be hashed; avoid logging tokens. Use Passport::tokensExpireIn() wisely.
Grant Misconfiguration Medium Incorrect grant types (e.g., enabling Password Grant for public APIs) can expose vulnerabilities. Audit with php artisan passport:keys.
Performance Bottlenecks Low-Medium Token revocation queries can be slow; consider softDeletes or Redis for large-scale systems.
Version Lock-in Low Laravel’s semantic versioning ensures backward compatibility; major upgrades (e.g., v12→v13) require testing.

Key Questions for Stakeholders:

  1. Auth Flow Requirements:
    • Do you need PKCE (for SPAs/mobile) or Client Credentials (for server-to-server)?
    • Will you support device codes (e.g., for IoT) or refresh tokens?
  2. Token Storage:
    • Will tokens be stored in DB only, Redis, or a hybrid approach?
    • What’s the token TTL (e.g., 1 hour for access tokens, 30 days for refresh tokens)?
  3. User Model Compatibility:
    • Can your user model implement OAuthenticatable without breaking existing auth?
    • Do you need custom scopes or token claims (e.g., sub, groups)?
  4. Deployment:
    • Will you use Passport’s built-in UI (for admin clients) or a custom solution?
    • How will you handle key rotation (e.g., passport:keys --force) in production?
  5. Monitoring:
    • Do you need audit logs for token issuance/revocation? (Extend Token model.)
    • Will you integrate with SIEM tools (e.g., Splunk) for OAuth2 events?

Integration Approach

Stack Fit

Component Compatibility Notes
Laravel Core Native Designed for Laravel’s service container, Eloquent, and routing.
PHP 8.2+ High v13.x requires PHP 8.2+; v12.x supports 8.1.
Databases High MySQL, PostgreSQL, SQLite (via Eloquent).
Caching Optional Redis recommended for token storage (via Passport::tokensCanBeRevoked()).
Queues Optional Async token revocation possible with Laravel Queues.
Frontend High Works with React, Vue, mobile apps (via OAuth2 flows).
API Gateways High Acts as an OAuth2 provider for Kong, Apigee, or custom gateways.

Recommended Stack for New Projects:

  • Laravel 10/11 + Passport v13.x
  • Redis for token storage (configurable via Passport::tokensCanBeRevoked()).
  • PostgreSQL/MySQL with UUID extensions (for oauth_clients table).
  • PHP 8.3 for latest features (e.g., enums in v13.x).

Migration Path

For Greenfield Projects

  1. Setup:
    composer require laravel/passport
    php artisan passport:install
    php artisan migrate
    
  2. Configure:
    • Add Passport::routes() to AuthServiceProvider.
    • Implement OAuthenticatable on user model.
    • Publish config: php artisan vendor:publish --provider="Laravel\Passport\PassportServiceProvider".
  3. Test:
    • Use Passport::actingAs() for testing.
    • Validate token endpoints (/oauth/token, /oauth/authorize).

For Existing Laravel Apps

  1. Assess:
    • Audit current auth (e.g., session-based, API tokens).
    • Identify OAuth2 grants needed (e.g., Authorization Code for SPAs).
  2. Migrate:
    • Run php artisan passport:install (creates migrations).
    • Update user model to implement OAuthenticatable.
    • Replace custom token logic with Passport’s middleware.
  3. Deprecate:
    • Phase out legacy auth (e.g., API keys) in favor of OAuth2.
    • Use Passport::tokensCanBeRevoked() to invalidate old tokens.

For Monolithic Apps

  • Hybrid Approach:
    • Use Passport only for API routes (prefix with /api).
    • Keep session auth for web routes.
    • Example middleware:
      Route::middleware(['auth:api', 'passport'])->group(function () {
          // API routes using OAuth2
      });
      

Compatibility

Scenario Compatibility Workarounds
Laravel 9.x Medium Use Passport v12.x; may require manual migrations for v13.x features.
Custom User Models High Implement OAuthenticatable and findForPassport().
Non-UUID Primary Keys Medium Configure Passport::useUUIDs(false) (but lose some features like client confidentiality).
Third-Party OAuth Clients High Clients can register via API (/oauth/clients) or manually.
Legacy Token Systems Low-Medium Use Passport::tokensCanBeRevoked() to invalidate old tokens during migration.
Multi-Tenancy High Scope tokens to tenants via custom claims or middleware.

**Breaking Changes

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata