PHPackages                             allcaretravel/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. allcaretravel/guzzle-oauth2-plugin

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

allcaretravel/guzzle-oauth2-plugin
==================================

An OAuth2 middleware for Guzzle

v4.0.0(5y ago)0322MITPHPPHP &gt;=7.1

Since May 20Pushed 5y agoCompare

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

READMEChangelogDependencies (3)Versions (23)Used By (0)

[![logo](https://camo.githubusercontent.com/7ca07ccc691ed4bc2a82b04aeaa7ebd9e77f64d130a6bb0ea3ad29da84371b2f/687474703a2f2f7777772e4163742e636f2e756b2f686f6d65706167652f696d616765732f4163742e706e67)](https://camo.githubusercontent.com/7ca07ccc691ed4bc2a82b04aeaa7ebd9e77f64d130a6bb0ea3ad29da84371b2f/687474703a2f2f7777772e4163742e636f2e756b2f686f6d65706167652f696d616765732f4163742e706e67)

Sainsbury's guzzle-oauth2-plugin
================================

[](#sainsburys-guzzle-oauth2-plugin)

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

[![Build Status](https://camo.githubusercontent.com/31239d10b689ff81cd5a36bb6e1ecfea3841d30e5ba4ab31e13a6bd5ab25b37c/68747470733a2f2f7472617669732d63692e6f72672f4163742f67757a7a6c652d6f61757468322d706c7567696e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Act/guzzle-oauth2-plugin)[![Code Coverage](https://camo.githubusercontent.com/877e743893ab543b85ef380db05c29a30eeaec6d38cdc4093643a23ccd084a9e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4163742f67757a7a6c652d6f61757468322d706c7567696e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Act/guzzle-oauth2-plugin/?branch=master)

Version 3.x (on the `master` branch) is intended for Guzzle 6:

```
        "Act/guzzle-oauth2-plugin": "^3.0"
```

Version 2.x (on the `release/2.0` branch) is intended for Guzzle 5:

```
        "Act/guzzle-oauth2-plugin": "^2.0"
```

Version 1.x (on the `release/1.0` branch) is intended for Guzzle 3 \[Unmaintained\]:

```
        "Act/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 `.vendor/bin/phpunit`.

Example
-------

[](#example)

```
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Act\Guzzle\Oauth2\GrantType\RefreshToken;
use Act\Guzzle\Oauth2\GrantType\PasswordCredentials;
use Act\Guzzle\Oauth2\Middleware\OAuthMiddleware;

$baseUri = 'https://example.com';
$config = [
    PasswordCredentials::CONFIG_USERNAME => 'test@example.com',
    PasswordCredentials::CONFIG_PASSWORD => 'test password',
    PasswordCredentials::CONFIG_CLIENT_ID => 'test-client',
    PasswordCredentials::CONFIG_TOKEN_URL => '/oauth/token',
    'scope' => 'administration',
];

$oauthClient = new Client(['base_uri' => $baseUri]);
$grantType = new PasswordCredentials($oauthClient, $config);
$refreshToken = new RefreshToken($oauthClient, $config);
$middleware = new OAuthMiddleware($oauthClient, $grantType, $refreshToken);

$handlerStack = HandlerStack::create();
$handlerStack->push($middleware->onBefore());
$handlerStack->push($middleware->onFailure(5));

$client = new Client(['handler'=> $handlerStack, 'base_uri' => $baseUri, 'auth' => 'oauth2']);

$response = $client->request('GET', '/api/user/me');

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

Example using Symfony DI config
-------------------------------

[](#example-using-symfony-di-config)

```

        https://example.com

            test@example.com
            test password
            test-client
            /oauth/token

                %acme.base_uri%

            %acme.oauth.config%

            %acme.oauth.config%

                        5

                %acme.base_uri%
                oauth2

```

###  Health Score

31

—

LowBetter than 70% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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 ~129 days

Recently: every ~310 days

Total

19

Last Release

1996d ago

Major Versions

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

v1.1.0 → v2.2.02016-05-20

v2.2.0 → v3.0.02016-05-20

v3.0.6 → v4.0.02020-10-06

PHP version history (2 changes)v3.0.3PHP &gt;=5.6

v3.0.6PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/db6694a3e838d346081d216f29dd7aeb037e67ea2123391f263e060a903ded2e?d=identicon)[semsphy](/maintainers/semsphy)

---

Top Contributors

[![pjcdawkins](https://avatars.githubusercontent.com/u/1465106?v=4)](https://github.com/pjcdawkins "pjcdawkins (26 commits)")[![dm](https://avatars.githubusercontent.com/u/150041?v=4)](https://github.com/dm "dm (12 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)")[![pharman](https://avatars.githubusercontent.com/u/1065123?v=4)](https://github.com/pharman "pharman (4 commits)")[![Tobion](https://avatars.githubusercontent.com/u/610090?v=4)](https://github.com/Tobion "Tobion (4 commits)")[![fullpipe](https://avatars.githubusercontent.com/u/929659?v=4)](https://github.com/fullpipe "fullpipe (2 commits)")[![ibpavlov](https://avatars.githubusercontent.com/u/3340235?v=4)](https://github.com/ibpavlov "ibpavlov (1 commits)")[![allcaretravels](https://avatars.githubusercontent.com/u/46768956?v=4)](https://github.com/allcaretravels "allcaretravels (1 commits)")[![chx](https://avatars.githubusercontent.com/u/193045?v=4)](https://github.com/chx "chx (1 commits)")[![gregurco](https://avatars.githubusercontent.com/u/4052904?v=4)](https://github.com/gregurco "gregurco (1 commits)")[![adamgoose](https://avatars.githubusercontent.com/u/611068?v=4)](https://github.com/adamgoose "adamgoose (1 commits)")[![marfillaster](https://avatars.githubusercontent.com/u/121793?v=4)](https://github.com/marfillaster "marfillaster (1 commits)")[![Neirda24](https://avatars.githubusercontent.com/u/7036794?v=4)](https://github.com/Neirda24 "Neirda24 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[shopify/shopify-api

Shopify API Library for PHP

4624.6M12](/packages/shopify-shopify-api)[omniphx/forrest

A Laravel library for Salesforce

2744.3M8](/packages/omniphx-forrest)[xeroapi/xero-php-oauth2

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

1054.1M11](/packages/xeroapi-xero-php-oauth2)[commerceguys/guzzle-oauth2-plugin

An OAuth2 plugin (subscriber) for Guzzle

1231.8M17](/packages/commerceguys-guzzle-oauth2-plugin)[sainsburys/guzzle-oauth2-plugin

An OAuth2 middleware for Guzzle

393.0M20](/packages/sainsburys-guzzle-oauth2-plugin)[eelkevdbos/firebase-php

Firebase php wrapper for REST API

7628.7k](/packages/eelkevdbos-firebase-php)

PHPackages © 2026

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