MyGit

guzzle/oauth-subscriber

Fork: 89 Star: 243 (更新于 2024-05-20 00:21:15)

license: MIT

Language: PHP .

Signs Guzzle requests using OAuth 1.0 (Guzzle 6+)

最后发布版本: 0.6.0 ( 2021-07-13 20:01:45)

GitHub网址

======================= 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:

.. code-block:: javascript

{
    "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:

.. code-block:: php

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.

.. code-block:: php

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

.. code-block:: php

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']);

最近版本更新:(数据更新于 2024-05-26 05:01:01)

2021-07-13 20:01:45 0.6.0

2021-03-07 17:40:25 0.5.0

2020-07-01 16:00:11 0.4.0

guzzle/oauth-subscriber同语言 PHP最近更新仓库

2024-07-03 02:11:59 laravel/laravel

2024-06-26 20:49:20 snipe/snipe-it

2024-06-12 14:59:19 doctrine/dbal

2024-06-12 01:01:58 danielmiessler/SecLists

2024-06-11 19:29:09 coollabsio/coolify

2024-05-31 16:22:53 symfony/var-dumper