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.
HttpClient and standalone Guzzle instances, leveraging Laravel’s middleware stack (e.g., app/Http/Middleware/) for centralized OAuth handling.RetryMiddleware, TimeoutHandler) or custom logic (e.g., token refresh).HttpClient, GuzzleHttp\Client, or Illuminate\Support\Facades\Http.route()->parameters()).oauth option enable multi-tenancy or partner API use cases without client reconstruction.ext-openssl (common in Laravel deployments).GuzzleHttp\Middleware::retry()).config('services.twitter'))..env or a vault (e.g., HashiCorp Vault)?oauth option) be resolved (e.g., middleware, request attributes)?401 Unauthorized) be retried or logged? Integrate with Laravel’s App\Exceptions\Handler.vcr recordings) for OAuth 1.0 endpoints to avoid rate limits?ext-openssl is enabled for RSA-SHA1 support.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'),
])
),
]);
$response = $client->get('statuses/home_timeline.json', [
'auth' => 'oauth',
'oauth' => [
'token' => $request->token,
'token_secret' => $request->token_secret,
],
]);
$app->singleton(HandlerStack::class, fn() => HandlerStack::create()->push(
new Oauth1(config('services.twitter.oauth'))
));
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('...');
php -v) and Guzzle version (composer show guzzlehttp/guzzle) meet requirements (PHP 7.2.5+, Guzzle 7.11+).composer.json:
"require": {
"guzzlehttp/guzzle": "^7.11",
"guzzlehttp/oauth-subscriber": "^0.9.1"
}
composer update.config/services.php (e.g., twitter.oauth).'twitter' => [
'oauth' => [
'consumer_key' => env('TWITTER_CONSUMER_KEY'),
'consumer_secret' => env('TWITTER_CONSUMER_SECRET'),
'token' => env('TWITTER_TOKEN'),
'token_secret' => env('TWITTER_TOKEN_SECRET'),
],
],
AppServiceProvider@boot():
public function boot()
{
$this->app->singleton(HandlerStack::class, fn() => HandlerStack::create()->push(
new Oauth1(config('services.twitter.oauth'))
));
}
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]);
// ...
}
GuzzleHttp\Psr7\Request mocks).// Test non-finite float edge case
$request = new Request('GET', '/', [], 'body with float: 1.0e+100');
$stack->push(new Oauth1([...]));
$response = $stack->handle($request);
ext-openssl (enabled by default in Laravel Valet/Forge).RetryMiddleware, TimeoutHandler).token_secret for two-legged OAuth).How can I help you explore Laravel packages today?