PHPackages                             commerceguys/guzzle-oauth2-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. commerceguys/guzzle-oauth2-plugin

ActiveLibrary[HTTP &amp; Networking](/categories/http)

commerceguys/guzzle-oauth2-plugin
=================================

An OAuth2 plugin (subscriber) for Guzzle

v2.1.1(10y ago)1231.8M↓62.3%73[4 issues](https://github.com/commerceguys/guzzle-oauth2-plugin/issues)[4 PRs](https://github.com/commerceguys/guzzle-oauth2-plugin/pulls)19MITPHP

Since May 20Pushed 4y ago13 watchersCompare

[ Source](https://github.com/commerceguys/guzzle-oauth2-plugin)[ Packagist](https://packagist.org/packages/commerceguys/guzzle-oauth2-plugin)[ RSS](/packages/commerceguys-guzzle-oauth2-plugin/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (3)Versions (10)Used By (19)

guzzle-oauth2-plugin
====================

[](#guzzle-oauth2-plugin)

Provides an OAuth2 plugin (subscriber) for [Guzzle](http://guzzlephp.org/).

[![Build Status](https://camo.githubusercontent.com/b36ee25ccc67069204801055098762a6c57de4b0c3501efcd8964466a031f326/68747470733a2f2f7472617669732d63692e6f72672f636f6d6d65726365677579732f67757a7a6c652d6f61757468322d706c7567696e2e737667)](https://travis-ci.org/commerceguys/guzzle-oauth2-plugin)[![Code Coverage](https://camo.githubusercontent.com/f7c72721b50a3174a373949b334874180689d0bd4c8bdd601b7122dfb93fa598/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f6d6d65726365677579732f67757a7a6c652d6f61757468322d706c7567696e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/commerceguys/guzzle-oauth2-plugin/?branch=master)

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`](https://github.com/commerceguys/guzzle-oauth2-plugin/tree/1.0) branch:

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

Features
--------

[](#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
-----------------

[](#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
-------

[](#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.
```

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity55

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 51% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~71 days

Total

9

Last Release

3856d ago

Major Versions

v1.0.0 → v2.0.0-beta12015-02-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/621c34dbc1ad3ea00e09f6006aa9607d0046bf862182d59c66f1f18cb51c0f15?d=identicon)[bojanz](/maintainers/bojanz)

---

Top Contributors

[![pjcdawkins](https://avatars.githubusercontent.com/u/1465106?v=4)](https://github.com/pjcdawkins "pjcdawkins (26 commits)")[![bojanz](https://avatars.githubusercontent.com/u/330162?v=4)](https://github.com/bojanz "bojanz (9 commits)")[![omissis](https://avatars.githubusercontent.com/u/197604?v=4)](https://github.com/omissis "omissis (8 commits)")[![steffkes](https://avatars.githubusercontent.com/u/325361?v=4)](https://github.com/steffkes "steffkes (5 commits)")[![fullpipe](https://avatars.githubusercontent.com/u/929659?v=4)](https://github.com/fullpipe "fullpipe (2 commits)")[![marfillaster](https://avatars.githubusercontent.com/u/121793?v=4)](https://github.com/marfillaster "marfillaster (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/commerceguys-guzzle-oauth2-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/commerceguys-guzzle-oauth2-plugin/health.svg)](https://phpackages.com/packages/commerceguys-guzzle-oauth2-plugin)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k108.5M885](/packages/laravel-socialite)[xeroapi/xero-php-oauth2

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

1054.7M18](/packages/xeroapi-xero-php-oauth2)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[ellaisys/aws-cognito

Laravel Authentication using AWS Cognito (Web and API)

123256.9k1](/packages/ellaisys-aws-cognito)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
