PHPackages                             frankkessler/guzzle-oauth2-middleware - 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. frankkessler/guzzle-oauth2-middleware

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

frankkessler/guzzle-oauth2-middleware
=====================================

OAuth2 middleware for Guzzle - Built off of Commerceguys/guzzle-oauth2-plugin package

v0.1.1(9y ago)14153.4k↑50%14[2 issues](https://github.com/frankkessler/guzzle-oauth2-middleware/issues)[1 PRs](https://github.com/frankkessler/guzzle-oauth2-middleware/pulls)2MITPHPCI failing

Since Sep 23Pushed 6y ago2 watchersCompare

[ Source](https://github.com/frankkessler/guzzle-oauth2-middleware)[ Packagist](https://packagist.org/packages/frankkessler/guzzle-oauth2-middleware)[ RSS](/packages/frankkessler-guzzle-oauth2-middleware/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (8)Used By (2)

guzzle-oauth2-middleware
========================

[](#guzzle-oauth2-middleware)

Adapted from Commerceguys/guzzle-oauth2-plugin Provides an OAuth2 middleware for [Guzzle](http://guzzlephp.org/) version 6+.

[![Build Status](https://camo.githubusercontent.com/d8209fedcd612ade26bca1dda916ee5731bee526cfbfe746b7b49cba1ca35255/68747470733a2f2f7472617669732d63692e6f72672f6672616e6b6b6573736c65722f67757a7a6c652d6f61757468322d6d6964646c65776172652e737667)](https://travis-ci.org/frankkessler/guzzle-oauth2-middleware)[![Coverage Status](https://camo.githubusercontent.com/ab035a3591e43c437573cb0d6d837565164cd219c8fddfebb74da70c320af91e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6672616e6b6b6573736c65722f67757a7a6c652d6f61757468322d6d6964646c65776172652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/frankkessler/guzzle-oauth2-middleware?branch=master)[![StyleCI](https://camo.githubusercontent.com/3d3aca67dfd4c3272a4cb2d5b3839ffeb5894ef2ddf087f1b8b11a87cddeb298/68747470733a2f2f7374796c6563692e696f2f7265706f732f36383932363632362f736869656c64)](https://styleci.io/repos/68926626)[![Latest Stable Version](https://camo.githubusercontent.com/7cd49378429ca26adb858b673cb569016ad95e1ad88c3f81910f1d8b032cd68b/68747470733a2f2f706f7365722e707567782e6f72672f6672616e6b6b6573736c65722f67757a7a6c652d6f61757468322d6d6964646c65776172652f762f737461626c65)](https://packagist.org/packages/frankkessler/guzzle-oauth2-middleware)

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)

On Windows, you must put the openssl.cnf file that comes with your version of PHP at the following location:

```
C:\usr\local\ssl\openssl.cnf

```

First make sure you have all the dependencies in place by running `composer install --prefer-dist`. You'll also need node installed to run the tests. You can simply run `make test` to start the node server, run the tests and then shut down the node server.

Alternatively, if you would like to run the node server in debug mode, you can run `node tests/server.js 8126 true` and then run `vendor/bin/phpunit` to run the tests.

Example
-------

[](#example)

```
use GuzzleHttp\Client;
use Frankkessler\Guzzle\Oauth2\GrantType\RefreshToken;
use Frankkessler\Guzzle\Oauth2\GrantType\PasswordCredentials;
use Frankkessler\Guzzle\Oauth2\Oauth2Client;

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

$client = new Oauth2Client(['base_uri' => $base_uri]);

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

$token = new PasswordCredentials($config);
$client->setGrantType($token);

$refreshToken = new RefreshToken($config);
$client->setRefreshTokenGrantType($refreshToken);

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

$response_headers = $response->getHeaders();

$response_code = $response->getStatusCode();

$response_body = (string) $response->getBody();

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

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~12 days

Total

2

Last Release

3506d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/80184c74c57baaff6ac4e3ef7152c2db3d79719f69fafe1fdcc346f4837a402a?d=identicon)[frankkessler](/maintainers/frankkessler)

---

Top Contributors

[![frankkessler](https://avatars.githubusercontent.com/u/1131687?v=4)](https://github.com/frankkessler "frankkessler (23 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/frankkessler-guzzle-oauth2-middleware/health.svg)

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

###  Alternatives

[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[akamai-open/edgegrid-client

Implements the Akamai {OPEN} EdgeGrid Authentication specified by https://developer.akamai.com/introduction/Client\_Auth.html

482.5M6](/packages/akamai-open-edgegrid-client)[muhammadhuzaifa/telescope-guzzle-watcher

Telescope Guzzle Watcher provide a custom watcher for intercepting http requests made via guzzlehttp/guzzle php library. The package uses the on\_stats request option for extracting the request/response data. The watcher intercept and log the request into the Laravel Telescope HTTP Client Watcher.

98239.8k1](/packages/muhammadhuzaifa-telescope-guzzle-watcher)[ory/hydra-client-php

Documentation for all of Ory Hydra's APIs.

1710.8k](/packages/ory-hydra-client-php)[meteocontrol/vcom-api-client

HTTP Client for meteocontrol's VCOM API - The VCOM API enables you to directly access your data on the meteocontrol platform.

175.7k1](/packages/meteocontrol-vcom-api-client)

PHPackages © 2026

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