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

Oauth Subscriber Laravel Package

guzzlehttp/oauth-subscriber

Guzzle middleware for OAuth 1.0 request signing (consumer key/secret + token/secret) compatible with Guzzle 7.11+ and PHP 7.2.5+. Add to a HandlerStack, set auth=oauth, and optionally override token credentials per request.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Middleware Integration: Perfectly aligns with Laravel’s Guzzle-based HttpClient and standalone Guzzle instances, leveraging Laravel’s middleware stack (e.g., app/Http/Middleware/) for centralized OAuth handling.
  • OAuth 1.0 Legacy Support: Critical for APIs like Twitter v1.1, Mailchimp, or legacy payment gateways where OAuth 2.0 is unavailable. The package’s OAuth 1.0a compliance ensures compatibility.
  • Extensibility: Middleware design allows stacking with Laravel’s built-in middleware (e.g., RetryMiddleware, TimeoutHandler) or custom logic (e.g., token refresh).
  • PHP 8.5 Stability: Fixes non-finite float coercion warnings, eliminating runtime issues during upgrades without architectural changes.

Integration Feasibility

  • Laravel Ecosystem: Zero Laravel-specific dependencies; integrates seamlessly with HttpClient, GuzzleHttp\Client, or Illuminate\Support\Facades\Http.
  • Configuration: Supports both global (client-level) and per-request OAuth signing, aligning with Laravel’s request-scoped configurations (e.g., route()->parameters()).
  • PSR Standards: Compatible with PSR-7 (Guzzle 7+) and PSR-18 (PHP 8.1+), ensuring future-proofing.
  • Dynamic Credentials: Per-request token/secret overrides via oauth option enable multi-tenancy or partner API use cases without client reconstruction.

Technical Risk

  • Security:
    • Mitigated: Fixes CVE-2025-21617 (nonce entropy) and validates RSA keys upfront. RSA-SHA1 requires ext-openssl (common in Laravel deployments).
    • Residual: OAuth 1.0’s statelessness may require custom retry logic for token expiration (e.g., GuzzleHttp\Middleware::retry()).
  • Deprecation: No risk; Guzzle 6.x is unsupported, but Laravel’s default Guzzle 7+ is unaffected.
  • PHP 8.5: Non-finite float fix ensures stability, but edge cases (e.g., custom middleware interactions) should be tested.
  • Complexity: OAuth 1.0’s manual signature generation remains the primary complexity, but Laravel’s service container can abstract credential storage (e.g., config('services.twitter')).

Key Questions

  1. API Strategy: Are there plans to migrate from OAuth 1.0 to OAuth 2.0 for any integrated APIs? If not, this package is a long-term fit.
  2. Credential Management:
    • How will secrets (consumer/token) be stored? Laravel’s .env or a vault (e.g., HashiCorp Vault)?
    • For multi-tenancy, how will dynamic credentials (e.g., oauth option) be resolved (e.g., middleware, request attributes)?
  3. Performance:
    • Will RSA-SHA1 signing impact latency for high-throughput APIs? Benchmark against HMAC-SHA256 if possible.
    • Are there plans to offload signing to a dedicated service (e.g., AWS Lambda) for scalability?
  4. Error Handling:
    • How will failed OAuth signatures (e.g., 401 Unauthorized) be retried or logged? Integrate with Laravel’s App\Exceptions\Handler.
    • Should token refresh logic (e.g., for expired tokens) be implemented as middleware or a service?
  5. Testing:
    • Should PHP 8.5-specific tests (e.g., non-finite float edge cases) be added to the test suite?
    • Are there mock APIs (e.g., vcr recordings) for OAuth 1.0 endpoints to avoid rate limits?
  6. Upgrade Path:
    • With PHP 8.5 support, should teams on PHP 8.4 or earlier prioritize upgrades to leverage this release?
    • If using Laravel Forge/Vapor, ensure ext-openssl is enabled for RSA-SHA1 support.

Integration Approach

Stack Fit

  • Laravel HTTP Client:
    • Preferred: Use HttpClient::withOptions() to inject the middleware globally:
      $client = HttpClient::withOptions([
          'handler' => HandlerStack::create()->push(
              new Oauth1([
                  'consumer_key'    => config('services.twitter.key'),
                  'consumer_secret' => config('services.twitter.secret'),
                  'token'           => config('services.twitter.token'),
                  'token_secret'    => config('services.twitter.token_secret'),
              ])
          ),
      ]);
      
    • Per-Request: Override credentials dynamically:
      $response = $client->get('statuses/home_timeline.json', [
          'auth' => 'oauth',
          'oauth' => [
              'token'        => $request->token,
              'token_secret' => $request->token_secret,
          ],
      ]);
      
  • Service Container:
    • Bind the middleware to the container for dependency injection:
      $app->singleton(HandlerStack::class, fn() => HandlerStack::create()->push(
          new Oauth1(config('services.twitter.oauth'))
      ));
      
  • Facade Integration:
    • Extend Laravel’s Http facade to auto-apply OAuth:
      Http::macro('oauth', function ($credentials) {
          return Http::withOptions([
              'handler' => HandlerStack::create()->push(
                  new Oauth1($credentials)
              ),
          ]);
      });
      
      Usage:
      $response = Http::oauth(config('services.twitter.oauth'))->get('...');
      

Migration Path

  1. Assessment:
    • Audit existing OAuth 1.0 integrations (e.g., Twitter, Mailchimp) to confirm compatibility.
    • Verify PHP version (php -v) and Guzzle version (composer show guzzlehttp/guzzle) meet requirements (PHP 7.2.5+, Guzzle 7.11+).
  2. Dependency Update:
    • Update composer.json:
      "require": {
          "guzzlehttp/guzzle": "^7.11",
          "guzzlehttp/oauth-subscriber": "^0.9.1"
      }
      
    • Run composer update.
  3. Configuration:
    • Move credentials to config/services.php (e.g., twitter.oauth).
    • Example:
      'twitter' => [
          'oauth' => [
              'consumer_key'    => env('TWITTER_CONSUMER_KEY'),
              'consumer_secret' => env('TWITTER_CONSUMER_SECRET'),
              'token'           => env('TWITTER_TOKEN'),
              'token_secret'    => env('TWITTER_TOKEN_SECRET'),
          ],
      ],
      
  4. Middleware Injection:
    • For global use, bind the middleware in AppServiceProvider@boot():
      public function boot()
      {
          $this->app->singleton(HandlerStack::class, fn() => HandlerStack::create()->push(
              new Oauth1(config('services.twitter.oauth'))
          ));
      }
      
    • For per-request use, inject the middleware into controllers/services:
      use GuzzleHttp\Subscriber\Oauth\Oauth1;
      
      public function __construct(private HandlerStack $stack) {}
      
      public function fetchTimeline()
      {
          $this->stack->push(new Oauth1(config('services.twitter.oauth')));
          $client = new Client(['handler' => $this->stack]);
          // ...
      }
      
  5. Testing:
    • Add tests for OAuth signing (e.g., using GuzzleHttp\Psr7\Request mocks).
    • Test PHP 8.5 compatibility if upgrading:
      // Test non-finite float edge case
      $request = new Request('GET', '/', [], 'body with float: 1.0e+100');
      $stack->push(new Oauth1([...]));
      $response = $stack->handle($request);
      

Compatibility

  • Laravel Versions: Compatible with Laravel 8+ (Guzzle 7+). For Laravel 7, use Guzzle 6.x and a fork of this package.
  • PHP Extensions: RSA-SHA1 requires ext-openssl (enabled by default in Laravel Valet/Forge).
  • Guzzle Middleware: Works alongside Laravel’s built-in middleware (e.g., RetryMiddleware, TimeoutHandler).
  • PSR-7: Fully compatible with Guzzle 7+ and PSR-7 implementations.

Sequencing

  1. Phase 1: Global Integration
    • Implement middleware binding for high-frequency APIs (e.g., Twitter).
    • Test with a non-production environment.
  2. Phase 2: Per-Request Overrides
    • Add dynamic credential switching for multi-tenancy or partner APIs.
    • Validate edge cases (e.g., empty token_secret for two-legged OAuth).
  3. Phase 3: Error Handling
    • Implement retry logic for failed signatures (e.g., expired tokens).
    • Integrate with Laravel’s exception handler for logging.
  4. **Phase 4: PHP
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
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