trikoder/oauth2-bundle
Symfony bundle that turns your application into an OAuth2 authorization server, integrating the PHP oauth2-server library with Symfony security, Doctrine-backed storage, and dependency injection configuration for issuing access and refresh tokens.
The first thing to internalize: this is a Symfony bundle, not a Laravel package. Do not try to composer require it into a Laravel app expecting a service provider and config file — it registers through Symfony's Bundle lifecycle and depends on Symfony's DI container and Doctrine. In a Laravel context you generally consume the underlying library, league/oauth2-server (which this bundle wraps), or you reach for Laravel Passport (which historically wrapped the same library).
Minimal path that actually fits a Laravel developer:
docs/ and src/DependencyInjection/TrikoderOAuth2Extension.php to see the config schema (grants, keys, token TTLs, storage).ClientCredentialsGrant end-to-end — it's the simplest flow and shows how the bundle wires a grant, a repository, and the AuthorizationServer service.First real use case: a dedicated OAuth2 server for machine-to-machine or third-party access, where Laravel apps are resource consumers validating bearer tokens via league/oauth2-server's ResourceServer and BearerTokenValidator (using only the public key and a thin middleware).
OAuth2AuthorizationServer (issues tokens) from OAuth2ResourceServer (validates them). Mirror that split in Laravel: an issuing service provider and a validating middleware. Don't merge them.CryptKey with public/private key paths (or raw PEM). In Laravel, load paths from config, never commit keys, and keep them outside the webroot with restrictive permissions.ClientRepositoryInterface, AccessTokenRepositoryInterface, RefreshTokenRepositoryInterface, AuthCodeRepositoryInterface, and ScopeRepositoryInterface, plus the resource-side equivalents.client_credentials for M2M, authorization_code + refresh_token for user-facing apps, password only for legacy migrations. Each grant type class is independently configurable in the bundle, which is a good pattern to copy.ResourceServer + one middleware. Resist re-implementing token issuance there.artisan vendor:publish, no facade, no auto-discovery. Composer will install it and nothing will happen — that's expected, not a bug.league/oauth2-server, which is maintained more actively. Prefer the underlying library for new work and pin carefully if you do use the bundle; watch upstream advisories.CryptKey accepts a path or raw PEM, with different passphrase semantics for each. A trailing newline, missing permissions, or wrong format surfaces as an opaque "unable to read key" error. Verify with openssl rsa -in key.pem -check before blaming the code.kid resolution. If tokens are opaque, you need a shared or remote store — pick deliberately and document it.BearerTokenValidator enforces exp/nbf. On multi-host setups without tight NTP you get intermittent, hard-to-reproduce 401s. Log exp, nbf, and server time together when debugging this.OAuthServerException with specific error codes. Catch it explicitly at the AuthorizationServer/ResourceServer seam and log grant type, client, scope, and error — don't let it bubble up as a generic 500.How can I help you explore Laravel packages today?