benjaminfavre/oauth2-http-client
Lightweight OAuth 2 decorator for Symfony HttpClient. Supports standard grant types, fetches and caches access tokens, injects them into requests, and can retry on token expiry. Minimal dependencies (Symfony Contracts + PHP JSON) and highly customizable auth steps.
HttpClient, Guzzle, or Symfony HTTP Client via bridges like symfony/http-client-laravel).Auth or Http facades.symfony/http-client-laravel (if available) or manual wrapper classes.HttpClient (built on Guzzle) can be extended to support Symfony decorators via adapters.Kernel.php) for global OAuth2 handling, similar to how Authenticate middleware works.cache, session, or database) requires custom implementation unless the package supports Laravel’s storage mechanisms.HttpClient (Guzzle-based) without duplication?BearerTokenMiddleware)?401 Unauthorized, 403 Forbidden) surfaced in Laravel’s exception handling (e.g., Illuminate\Http\Client\ConnectionException)?HttpClient with BearerTokenMiddleware may suffice.symfony/http-client-laravel) or custom wrapper.^6.0. Laravel’s symfony/http-client-laravel (if available) should handle version alignment.HttpClient, create an adapter to wrap Symfony decorators around Guzzle requests.oauth2.token.refreshing) for observability.benjaminfavre/oauth2-http-client and symfony/http-client (or bridge).config/app.php to resolve Symfony services if needed.AppServiceProvider).// app/Http/Kernel.php
protected $middlewareGroups = [
'api' => [
\App\Http\Middleware\AuthenticateOAuth2::class, // Custom middleware using the decorator
],
];
GithubClient, StripeClient) extending the decorator.Http facade or manual requests.README.md.config for OAuth2 settings (e.g., config/services.php).HTTP_CLIENT_VERBOSITY environment variable.HttpClient exceptions may need mapping to OAuth2-specific errors.oauth2-fallback middleware for critical paths if the decorator fails.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Token expiration | API requests fail with 401 |
Implement auto-refresh via decorator or job. |
| Network issues (OAuth2 provider) | Timeouts or 5xx errors |
Retry logic with exponential backoff. |
| Package incompatibility | Breaks HTTP requests | Feature flags to toggle decorator usage. |
| Token storage corruption | Invalid tokens issued | Use Laravel’s cache with TTL or database. |
| Symfony HTTP Client updates | Breaking changes | Pin versions in composer.json. |
OAuth2Client facade or helper class to abstract decorator usage.$client = app(OAuth2Client::class)->for('github');
$response = $client->get('user');
curl).README (if open-source).How can I help you explore Laravel packages today?