• Stars
    star
    241
  • Rank 167,643 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Signs Guzzle requests using OAuth 1.0 (Guzzle 6+)

Guzzle OAuth Subscriber

Signs HTTP requests using OAuth 1.0. Requests are signed using a consumer key, consumer secret, OAuth token, and OAuth secret.

This version only works with Guzzle 6.0 and up!

Installing

This project can be installed using Composer. Add the following to your composer.json:

{
    "require": {
        "guzzlehttp/oauth-subscriber": "^0.6"
    }
}

Using the Subscriber

Here's an example showing how to send an authenticated request to the Twitter REST API:

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Subscriber\Oauth\Oauth1;

$stack = HandlerStack::create();

$middleware = new Oauth1([
    'consumer_key'    => 'my_key',
    'consumer_secret' => 'my_secret',
    'token'           => 'my_token',
    'token_secret'    => 'my_token_secret'
]);
$stack->push($middleware);

$client = new Client([
    'base_uri' => 'https://api.twitter.com/1.1/',
    'handler' => $stack
]);

// Set the "auth" request option to "oauth" to sign using oauth
$res = $client->get('statuses/home_timeline.json', ['auth' => 'oauth']);

You can set the auth request option to oauth for all requests sent by the client by extending the array you feed to new Client with auth => oauth.

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Subscriber\Oauth\Oauth1;

$stack = HandlerStack::create();

$middleware = new Oauth1([
    'consumer_key'    => 'my_key',
    'consumer_secret' => 'my_secret',
    'token'           => 'my_token',
    'token_secret'    => 'my_token_secret'
]);
$stack->push($middleware);

$client = new Client([
    'base_uri' => 'https://api.twitter.com/1.1/',
    'handler' => $stack,
    'auth' => 'oauth'
]);

// Now you don't need to add the auth parameter
$res = $client->get('statuses/home_timeline.json');

Note

You can set the token and token_secret options to an empty string to use two-legged OAuth.

Using the RSA-SH1 signature method

use GuzzleHttp\Subscriber\Oauth\Oauth1;

$stack = HandlerStack::create();

$middleware = new Oauth1([
    'consumer_key'    => 'my_key',
    'consumer_secret' => 'my_secret',
    'private_key_file' => 'my_path_to_private_key_file',
    'private_key_passphrase' => 'my_passphrase',
    'signature_method' => Oauth1::SIGNATURE_METHOD_RSA,
]);
$stack->push($middleware);

$client = new Client([
    'handler' => $stack
]);

$response = $client->get('http://httpbin.org', ['auth' => 'oauth']);

More Repositories

1

guzzle

Guzzle, an extensible PHP HTTP client
PHP
23,172
star
2

promises

Promises/A+ library for PHP with synchronous support
PHP
7,584
star
3

RingPHP

[DEPRECATED] Simple handler system used to power clients and servers in PHP (this project is no longer used in Guzzle 6+)
PHP
843
star
4

streams

[DEPRECATED] Provides a simple abstraction over streams of data
PHP
637
star
5

guzzle-services

Provides an implementation of the Guzzle Command library that uses Guzzle service descriptions to describe web services, serialize requests, and parse responses into easy to use model structures.
PHP
251
star
6

guzzle_sphinx_theme

Sphinx theme used by Guzzle
HTML
169
star
7

guzzle3

[DEPRECATED] This is end of life and not maintained. Migrate to https://github.com/guzzle/guzzle
PHP
150
star
8

uri-template

PHP
138
star
9

command

Provides the foundation for building web service clients with Guzzle
PHP
110
star
10

cache-subscriber

[DEPRECATED] Private transparent proxy cache that caches HTTP responses (Guzzle 5+)
PHP
63
star
11

retry-subscriber

[DEPRECATED] Retries failed requests using customizable retry strategies. Guzzle 4/5 only.
PHP
61
star
12

log-subscriber

[DEPRECATED] Logs HTTP requests and Responses as they are sent over the wire. Not used in Guzzle 6.
PHP
43
star
13

progress-subscriber

[DEPRECATED] Emits upload and download progress events (Guzzle 4)
PHP
19
star
14

message-integrity-subscriber

[DEPRECATED] Verifies the integrity of HTTP responses using customizable validators. Guzzle 4/5.
PHP
12
star
15

test-server

A node.js server and a PHP controller class one can use when testing
JavaScript
8
star
16

.github

Default community health files
3
star