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

Plugin Oauth Laravel Package

guzzle/plugin-oauth

Guzzle OAuth plugin adding OAuth 1.0 request signing to your HTTP clients. Helps authenticate against APIs requiring OAuth headers or query params by attaching the proper signature to outgoing requests. Suitable for legacy OAuth 1 services.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require guzzle/plugin-oauth
    

    Ensure compatibility with Guzzle 3.x (this package is a subtree split of Guzzle’s OAuth plugin).

  2. Basic Usage Register the OAuth plugin with Guzzle’s client:

    use Guzzle\Plugin\OAuth\OAuth1;
    use Guzzle\Http\Client;
    
    $client = new Client();
    $client->addSubscriber(new OAuth1([
        'consumer_key'    => 'your_key',
        'consumer_secret' => 'your_secret',
        'token'           => 'user_token',
        'token_secret'    => 'user_token_secret',
    ]));
    
  3. First Request Use the client to make an authenticated request:

    $response = $client->get('https://api.example.com/protected-endpoint');
    

Implementation Patterns

Workflow: OAuth1 Integration

  1. Configuration Store credentials in .env or a config file:

    config([
        'services.oauth' => [
            'consumer_key'    => env('OAUTH_CONSUMER_KEY'),
            'consumer_secret' => env('OAUTH_CONSUMER_SECRET'),
            'token'           => env('OAUTH_TOKEN'),
            'token_secret'    => env('OAUTH_TOKEN_SECRET'),
        ],
    ]);
    
  2. Dynamic Plugin Attachment Attach the plugin conditionally (e.g., for API services):

    $client = new Client();
    if ($this->shouldUseOAuth()) {
        $client->addSubscriber(new OAuth1(config('services.oauth')));
    }
    
  3. Signing Requests The plugin automatically signs requests with OAuth1 parameters (e.g., oauth_signature, oauth_nonce).

Common Use Cases

  • API Clients: Secure API calls to services like Twitter, GitHub (Legacy), or custom OAuth1 endpoints.
  • Middleware: Extend Laravel’s HTTP client with OAuth1 support:
    $client = new Client(['base_url' => 'https://api.example.com']);
    $client->addSubscriber(new OAuth1(config('services.oauth')));
    

Gotchas and Tips

Pitfalls

  1. Guzzle 3.x Only This package does not support Guzzle 6/7. Ensure your project uses Guzzle 3.x or migrate to a modern OAuth package (e.g., league/oauth1-client).

  2. Signature Method OAuth1 requires a signature_method (default: HMAC-SHA1). Explicitly set it if the server expects a different method:

    new OAuth1([
        'signature_method' => 'PLAINTEXT', // Rare, but possible
    ]);
    
  3. Nonce and Timestamp The plugin auto-generates oauth_nonce and oauth_timestamp, but ensure your server’s clock is synchronized to avoid "stale nonce" errors.

Debugging Tips

  • Enable Guzzle Debugging Attach a debug subscriber to inspect signed requests:
    $client->addSubscriber(new \Guzzle\Plugin\Debug\DebugClient());
    
  • Validate Signatures Use tools like OAuth1 Playground to manually verify signatures.

Extension Points

  • Custom Signing Logic Extend OAuth1 to modify signature generation:
    class CustomOAuth1 extends OAuth1 {
        protected function getSignatureMethod() {
            return 'CUSTOM_METHOD';
        }
    }
    
  • Plugin Chaining Combine with other Guzzle plugins (e.g., Guzzle\Plugin\Cache) for caching OAuth-authenticated responses.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
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
christhompsontldr/laravel-inky