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

Oauth2 Openid Connect Server Laravel Package

steverhoades/oauth2-openid-connect-server

Laravel-friendly OAuth2 + OpenID Connect server built on League OAuth2. Provides OIDC discovery and JWT ID tokens, common grant types, and flexible storage/adapters so you can run your own authorization server for APIs and SSO.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Extensibility: The package integrates seamlessly with The PHP League’s OAuth2 Server, a battle-tested, modular framework. This aligns well with Laravel’s dependency injection and service container, enabling clean integration via Laravel’s Service Provider pattern.
  • OpenID Connect (OIDC) Support: Adds OIDC-specific features (e.g., ID tokens, userinfo endpoint, discovery) to an existing OAuth2 server, reducing reinvention. Ideal for projects requiring SSO, federated identity, or third-party auth delegation.
  • Laravel Synergy: Leverages Laravel’s built-in authentication scaffolding (e.g., Authenticatable, HasApiTokens) for user management, minimizing custom logic for token generation/validation.

Integration Feasibility

  • Low-Coupling Design: The package follows PSR-15 middleware and PSR-7 HTTP message standards, ensuring compatibility with Laravel’s middleware stack (e.g., Illuminate\Http\Middleware).
  • Configuration-Driven: Key behaviors (e.g., token signing, claims mapping) are configurable via YAML/JSON, fitting Laravel’s config/ structure. Example:
    // config/oauth.php
    'openid' => [
        'issuer' => env('APP_URL'),
        'claims' => ['sub', 'name', 'email'],
    ],
    
  • Database Agnostic: Works with any Laravel-supported database (MySQL, PostgreSQL, SQLite) via Eloquent models or custom storage adapters.

Technical Risk

  • Token Signing Dependencies: Relies on Elliptic Curve Digital Signature Algorithm (ECDSA) or RSA for JWT signing. Laravel’s default openssl extension must be enabled; fallback to libraries like firebase/php-jwt may be needed if native support is lacking.
  • State Management: OIDC’s state parameter requires secure storage (e.g., Redis) to prevent CSRF. Laravel’s session or cache drivers can mitigate this, but performance implications exist at scale.
  • Discovery Endpoint: The .well-known/openid-configuration endpoint must be publicly accessible. Laravel’s route caching and middleware groups (e.g., web) may need adjustment to expose it without auth.
  • Userinfo Endpoint: Requires a UserEntity interface. Laravel’s User model can implement this, but custom fields (e.g., avatar_url) may need mapping logic.

Key Questions

  1. Authentication Backend: How will user identities be resolved? (e.g., Laravel’s users table, LDAP, or a custom provider?)
  2. Token Storage: Will refresh tokens be stored in the database, or will a stateless approach (e.g., JWT-only) be used?
  3. Performance: How will the userinfo endpoint scale with high read loads? (Caching strategies?)
  4. Security: Are there plans to enforce PKCE (Proof Key for Code Exchange) for public clients?
  5. Monitoring: How will token issuance/validation metrics be logged? (e.g., Laravel’s log channel or a dedicated service like Sentry?)
  6. Compliance: Does the project require GDPR or HIPAA compliance? If so, how will token revocation and data minimization be handled?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Native support for:
    • Middleware: Integrate OIDC validation into Laravel’s pipeline (e.g., auth:api).
    • Routing: Expose OIDC endpoints via Laravel’s router:
      Route::get('/.well-known/openid-configuration', [OIDCConfigController::class]);
      
    • Events: Extend Laravel’s Illuminate\Auth\Events for OIDC-specific hooks (e.g., OIDCLogin).
  • Dependencies:
    • league/oauth2-server: Core OAuth2 logic (already a Laravel-friendly package).
    • firebase/php-jwt: Fallback for JWT handling if openssl is unavailable.
    • symfony/http-foundation: For PSR-7 compatibility (Laravel 8+ includes this via symfony/http-client).

Migration Path

  1. Phase 1: Setup

    • Install the package via Composer:
      composer require steverhoades/oauth2-openid-connect-server
      
    • Publish and configure config/oauth.php:
      php artisan vendor:publish --provider="League\OAuth2\Server\Laravel\ServiceProvider"
      
    • Register the OAuth2 server in AppServiceProvider:
      $server = new \League\OAuth2\Server\Server(
          new \League\OAuth2\Server\ResourceServer(),
          new \League\OAuth2\Server\Grant\PasswordGrant(),
          new \League\OAuth2\Server\Storage\Pdo(),
          new \League\OAuth2\Server\CryptKey\PrivateKey(
              file_get_contents(storage_path('app/private.key')),
              null,
              'RS256'
          ),
          new \League\OAuth2\Server\CryptKey\PublicKey(
              file_get_contents(storage_path('app/public.key')),
              'RS256'
          )
      );
      
    • Add OIDC extension:
      $server->enableGrantType(
          new \Steverhoades\OIDC\Grant\PasswordGrant(),
          new \Steverhoades\OIDC\Grant\AuthorizationCodeGrant()
      );
      
  2. Phase 2: User Integration

    • Implement UserEntity interface for Laravel’s User model:
      class User extends Authenticatable implements UserEntity {
          public function getIdentifier() { return $this->id; }
          public function getUsername() { return $this->email; }
          public function getEmail() { return $this->email; }
          // ... other required methods
      }
      
    • Register the user provider with the OAuth2 server.
  3. Phase 3: Endpoint Exposure

    • Define routes for OIDC flows:
      Route::post('/oauth/token', [OAuthController::class, 'issueToken']);
      Route::get('/userinfo', [OAuthController::class, 'userInfo']);
      Route::get('/.well-known/openid-configuration', [OIDCConfigController::class]);
      
    • Apply middleware to protect routes (e.g., auth:api for /userinfo).
  4. Phase 4: Testing

    • Use Postman or OIDC debug tools (e.g., oidcdebugger.com) to validate flows.
    • Test edge cases: token revocation, expired sessions, malformed requests.

Compatibility

  • Laravel Versions: Tested with Laravel 8+ (PHP 8.0+). Laravel 7 may require polyfills for PSR-15.
  • Database: Works with Eloquent or custom storage (e.g., Redis for token storage).
  • Caching: Leverage Laravel’s cache() helper for userinfo responses to reduce database load.
  • Existing Auth: Can coexist with Laravel’s auth() helper; OIDC tokens can be mapped to Laravel sessions via middleware.

Sequencing

  1. Prerequisite: Ensure a working OAuth2 server (e.g., using league/oauth2-server).
  2. Core OIDC: Implement ID tokens and discovery endpoint.
  3. Userinfo: Add custom claims mapping.
  4. Clients: Register public/confidential clients in the OAuth2 server.
  5. Monitoring: Integrate logging (e.g., Laravel’s Log::channel('oidc')).

Operational Impact

Maintenance

  • Dependency Updates: Monitor league/oauth2-server and steverhoades/oauth2-openid-connect-server for breaking changes. Laravel’s composer update + testing pipeline mitigates risk.
  • Configuration Drift: Centralize OIDC settings in config/oauth.php to avoid hardcoded values.
  • Key Rotation: Automate private/public key rotation using Laravel’s scheduler:
    // app/Console/Commands/RotateOIDCKeys.php
    public function handle() {
        $this->generateNewKeys();
        $this->updateOAuthConfig();
    }
    

Support

  • Debugging: Use Laravel’s dd() or dump() for middleware inspection. Enable OAuth2 server debug mode:
    $server->setDebug(true);
    
  • Client-Side Issues: Provide SDK examples (e.g., axios for SPAs, requests-oauthlib for Python clients).
  • Documentation: Maintain a docs/oidc.md in the repo with:
    • Token endpoint examples.
    • Claim mapping guidelines.
    • Troubleshooting (e.g., "401 Unauthorized" → expired token).

Scaling

  • Stateless Tokens: Prefer JWT for scalability (avoid database-bound
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor