league/oauth2-server
Standards-compliant OAuth 2.0 authorization server for PHP. Protect APIs with bearer access tokens, issue and refresh tokens, and support common grants (auth code, client credentials, device, implicit, password, refresh) with PSR-7 interoperability and RFC support.
composer require league/oauth2-server. Ensure PHP ≥8.2, openssl, and json extensions are enabled.ClientEntityInterface, UserEntityInterface, and store clients/users in your DB. Use the provided AuthorizationServer class to handle token issuance and validation.ResourceServer. Accept only requests with valid Authorization: Bearer <token> headers.league/oauth2-server directly—configure via migration templates and the passport:install command.ClientRepositoryInterface, UserRepositoryInterface, ScopeRepositoryInterface) and inject them into AuthorizationServer and ResourceServer via factories or DI container.AuthorizationCodeGrant with $enableProofKey = true. This is critical for public clients (mobile/spa) and required for modern security.ScopeEntityInterface and use finalizeScopes() in your auth code grant logic to dynamically trim scopes based on client permissions or user consent.DeviceAuthorizationGrant (added in v9) for IoT and TV-like clients. Requires implementing DeviceCodeRepositoryInterface and a UI flow for user confirmation.string, int, bool) and return types strictly. Implementations must match exact signatures—PHPSpec/IDE linting is highly recommended.invalid_grant + HTTP 400 instead of invalid_request + HTTP 401—update your client-side error handling to treat both token types uniformly.CryptKey—never write raw keys to /tmp.Authorization: bearer ... now works). Ensure your middleware/proxy doesn’t uppercase headers before PHP receives them.RequestAccessTokenEvent, DeviceAuthorizationEvent) only for specific grants. Use listeners to log, audit, or mutate token issuance—but remember: events are not queued by default.finalizeScopes() only after the auth code is persisted. Don’t rely on DB writes inside finalizeScopes()—hook into persistence events (e.g., Doctrine lifecycle callbacks) instead.How can I help you explore Laravel packages today?