MyGit

guzzle/oauth-subscriber

Fork: 89 Star: 241 (更新于 2024-10-26 10:49:12)

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-10-23 10:41:14)

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-11-01 18:37:36 schmittjoh/JMSSerializerBundle

2024-10-31 21:37:53 filamentphp/filament

2024-10-28 00:16:41 symfony/var-dumper

2024-10-28 00:11:41 symfony/symfony

2024-10-11 23:44:26 coollabsio/coolify

2024-10-11 03:27:29 odan/slim4-skeleton