MyGit

commerceguys/guzzle-oauth2-plugin

Fork: 71 Star: 123 (更新于 2024-09-11 20:16:14)

license: MIT

Language: PHP .

Provides an OAuth2 plugin (subscriber) for Guzzle

最后发布版本: v2.1.0 ( 2015-05-29 04:18:54)

GitHub网址

guzzle-oauth2-plugin

Provides an OAuth2 plugin (subscriber) for Guzzle.

Build Status Code Coverage

Version 2.x (on the master branch) is intended for Guzzle 5:

        "commerceguys/guzzle-oauth2-plugin": "~2.0"

Guzzle 3 compatibility continues in the 1.0 branch:

        "commerceguys/guzzle-oauth2-plugin": "~1.0"

Features

  • Acquires access tokens via one of the supported grant types (code, client credentials, user credentials, refresh token). Or you can set an access token yourself.
  • Supports refresh tokens (stores them and uses them to get new access tokens).
  • Handles token expiration (acquires new tokens and retries failed requests).

Running the tests

First make sure you have all the dependencies in place by running composer install --prefer-dist, then simply run ./bin/phpunit.

Example

use GuzzleHttp\Client;
use CommerceGuys\Guzzle\Oauth2\GrantType\RefreshToken;
use CommerceGuys\Guzzle\Oauth2\GrantType\PasswordCredentials;
use CommerceGuys\Guzzle\Oauth2\Oauth2Subscriber;

$base_url = 'https://example.com';

$oauth2Client = new Client(['base_url' => $base_url]);

$config = [
    'username' => 'test@example.com',
    'password' => 'test password',
    'client_id' => 'test-client',
    'scope' => 'administration',
];

$token = new PasswordCredentials($oauth2Client, $config);
$refreshToken = new RefreshToken($oauth2Client, $config);

$oauth2 = new Oauth2Subscriber($token, $refreshToken);

$client = new Client([
    'defaults' => [
        'auth' => 'oauth2',
        'subscribers' => [$oauth2],
    ],
]);

$response = $client->get('https://example.com/api/user/me');

print_r($response->json());

// Use $oauth2->getAccessToken(); and $oauth2->getRefreshToken() to get tokens
// that can be persisted for subsequent requests.

最近版本更新:(数据更新于 2024-09-18 11:11:21)

2015-05-29 04:18:54 v2.1.0

2015-03-19 17:58:12 v2.0.0

commerceguys/guzzle-oauth2-plugin同语言 PHP最近更新仓库

2024-09-18 20:45:32 coollabsio/coolify

2024-09-17 03:04:08 caseyamcl/guzzle_retry_middleware

2024-09-16 23:17:15 cakephp/migrations

2024-09-14 10:53:46 cakephp/cakephp

2024-09-06 16:28:08 spatie/holidays

2024-09-06 02:33:26 CakeDC/users