guzzle/oauth-subscriber
Fork: 89 Star: 241 (更新于 2024-12-10 22:49:56)
license: MIT
Language: PHP .
Signs Guzzle requests using OAuth 1.0 (Guzzle 6+)
最后发布版本: 0.6.0 ( 2021-07-13 20:01:45)
======================= 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-12-13 19:38:03 coollabsio/coolify
2024-12-13 09:22:46 w7corp/easywechat
2024-12-11 20:15:22 symfony/symfony
2024-11-29 16:49:37 symfony/var-dumper
2024-11-20 23:58:25 laravel/framework
2024-11-20 18:39:23 danielmiessler/SecLists