league/oauth2-client
OAuth 2.0 client library for PHP. Provides a solid base for implementing “Sign in with …” flows and RFC 6749-compliant integrations, with a GenericProvider for bearer-token services and an extensible architecture for custom providers.
AuthServiceProvider, OAuthService). Its PSR-compliant design ensures clean separation of concerns.OAuthTokenRefreshed) for logging/auditing via Laravel’s event system.Http::macro()), caching (Redis), and configuration (.env). Supports Laravel’s queue system for async token refreshes.ProviderInterface.OAuthGuard) for route-level protection.Http::withOptions())..env for OAuth credentials (e.g., GOOGLE_CLIENT_ID).phpseclib or openssl for PKCE flows (if enabled).GoogleUser class.OAuthService) to wrap the client.Cache::remember()).composer require league/oauth2-client.config/services.php.league/oauth2-client directly in controllers/services.use League\OAuth2\Client\Provider\GoogleUser;
$provider = new GoogleUser([
'clientId' => config('services.google.client_id'),
'clientSecret' => config('services.google.client_secret'),
]);
$token = $provider->getAccessToken('authorization_code', ['code' => $request->code]);
composer update with testing.getAuthorizationUrl() → getAuthorizationUrlWithState()).info('OAuth token refreshed')).OAuth2\Client\Provider\Exception\IdentityProviderException).GoogleProviderService).throttle middleware for OAuth endpoints.| Failure | Impact | Mitigation |
|---|---|---|
| Expired Token | Broken API access | Auto-refresh via Laravel Queues + retries. |
| Provider Outage | Auth failures | Fallback to local auth (if hybrid system). |
| CSRF/PKCE Misconfiguration | Security vulnerabilities | Validate state/CSRF tokens via Laravel middleware. |
| Token Leak | Data breach | Use Laravel’s encryption for token storage. |
| Rate Limiting | API throttling | Implement exponential backoff in retries. |
invalid_grant)..env.How can I help you explore Laravel packages today?