PHPackages                             qbnk/guzzle5-oauth2-subscriber - 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. qbnk/guzzle5-oauth2-subscriber

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

qbnk/guzzle5-oauth2-subscriber
==============================

OAuth2 authentication and reauthorization for Guzzle 5.x - forked and based on nmrkt/guzzle5-oauth2-subscriber

v0.1.4(11y ago)010.2k11MITPHPPHP &gt;=5.4.0

Since Aug 6Pushed 11y ago1 watchersCompare

[ Source](https://github.com/QBNK/guzzle5-oauth2-subscriber)[ Packagist](https://packagist.org/packages/qbnk/guzzle5-oauth2-subscriber)[ RSS](/packages/qbnk-guzzle5-oauth2-subscriber/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (1)

guzzle-oauth2-subscriber
========================

[](#guzzle-oauth2-subscriber)

Forked from NMRKT/guzzle5-oauth2-subscriber and fixed a few bugs
----------------------------------------------------------------

[](#forked-from-nmrktguzzle5-oauth2-subscriber-and-fixed-a-few-bugs)

The NMRKT implementation seems abandoned as they have not responded to any of the merge requests. We then decided to publish our fixes.

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

Attribution
===========

[](#attribution)

---

This plugin is based on the Guzzle 3.x OAuth2 plugin by Bojan Zivanovic and Damien Tournoud from the [CommerceGuys guzzle-oauth2-plugin repository](https://github.com/commerceguys/guzzle-oauth2-plugin).

I originally forked that project, but moved to a new repo since most of the code has changed and I needed to reset the versions to &lt; 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).
- Allows storage and lookup of access tokens via callbacks

Usage
=====

[](#usage)

---

This plugin extends Guzzle, transparently adding authentication to outgoing requests and optionally attempting reauthorization if the access token is no longer valid.

There are several grant types available like `PasswordCredentials`, `ClientCredentials` and `AuthorizationCode`.

Access Token Method
-------------------

[](#access-token-method)

If you already have an access token, you can use that to authenticate to a service, but beware that access tokens are meant to expire, and the process of obtaining a new access token is included in this library as well (for example, by using the `PasswordCredentials` method).

Here's how to use an existing access token for the request, thus no re-authorization client is needed:

```
use kamermans\GuzzleOAuth2\OAuth2Subscriber;

// Setup OAuth
$oauth = new OAuth2Subscriber();

// Manually specify access_token.  When it expires, you will get an exception
$oauth->getTokenData()->accessToken = 'somelongtoken';

$client = new GuzzleHttp\Client();
// Attach OAuth subscriber to the Guzzle client and all URLs will be authenticated
$client->getEmitter()->attach($oauth);
$response = $client->get('http://somehost/some_secure_url');

echo "Status: ".$response->getStatusCode()."\n";
```

Client Credentials Method
-------------------------

[](#client-credentials-method)

Client credentials are normally used in server-to-server authentication. With this grant type, a client is requesting authorization in its own behalf, so there are only two parties involved. At a minimum, a `client_id` and `client_secret` are required, although many services require a `scope` and other parameters.

Here's an example of the client credentials method:

```
use kamermans\GuzzleOAuth2\GrantType\ClientCredentials;
use kamermans\GuzzleOAuth2\OAuth2Subscriber;

// Authorization client - this is used to request OAuth access tokens
$reauth_client = new GuzzleHttp\Client([
    // URL for access_token request
    'base_url' => 'http://some_host/access_token_request_url',
]);
$reauth_config = [
	"client_id" => "your client id",
	"client_secret" => "your client secret",
	"scope" => "your scope(s)", // optional
	"state" => time(), // optional
];
$grant_type = new ClientCredentials($reauth_client, $reauth_config);
$oauth = new OAuth2Subscriber($grant_type);

// This is the normal Guzzle client that you use in your application
$client = new GuzzleHttp\Client();
$client->getEmitter()->attach($oauth);
$response = $client->get('http://somehost/some_secure_url');

echo "Status: ".$response->getStatusCode()."\n";
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.6% 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 ~90 days

Total

4

Last Release

4031d ago

### Community

Maintainers

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

---

Top Contributors

[![kamermans](https://avatars.githubusercontent.com/u/266265?v=4)](https://github.com/kamermans "kamermans (10 commits)")[![fozcodes](https://avatars.githubusercontent.com/u/1767848?v=4)](https://github.com/fozcodes "fozcodes (7 commits)")[![codemedic](https://avatars.githubusercontent.com/u/691011?v=4)](https://github.com/codemedic "codemedic (1 commits)")[![MattKetmo](https://avatars.githubusercontent.com/u/334996?v=4)](https://github.com/MattKetmo "MattKetmo (1 commits)")

---

Tags

Guzzleprovideroauthoauth2subscriberguzzle5

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/qbnk-guzzle5-oauth2-subscriber/health.svg)

```
[![Health](https://phpackages.com/badges/qbnk-guzzle5-oauth2-subscriber/health.svg)](https://phpackages.com/packages/qbnk-guzzle5-oauth2-subscriber)
```

###  Alternatives

[guzzlehttp/oauth-subscriber

Guzzle OAuth 1.0 subscriber

24114.5M141](/packages/guzzlehttp-oauth-subscriber)[zoonman/linkedin-api-php-client

LinkedIn API PHP SDK with OAuth 2.0 &amp; CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.

127704.0k](/packages/zoonman-linkedin-api-php-client)

PHPackages © 2026

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