PHPackages                             kamermans/guzzle4-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. kamermans/guzzle4-oauth2-subscriber

Abandoned → [kamermans/guzzle-oauth2-subscriber](/?search=kamermans%2Fguzzle-oauth2-subscriber)Library[HTTP &amp; Networking](/categories/http)

kamermans/guzzle4-oauth2-subscriber
===================================

OAuth2 authentication and reauthorization for Guzzle 4.x and 5.x

v1.0(9y ago)486.6k6[1 PRs](https://github.com/kamermans/guzzle4-oauth2-subscriber/pulls)MITPHPPHP &gt;=5.4.0

Since Aug 6Pushed 9y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

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

[](#guzzle-oauth2-subscriber)

Provides an OAuth2 subscriber for [Guzzle](http://guzzlephp.org/) 4.x and 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

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 84.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 ~491 days

Total

3

Last Release

3316d ago

Major Versions

v0.1.1 → v1.02017-04-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/052bdc08c95ac7769aad18f1f294dcf02e4f44bc01ee108833f50ff470a53208?d=identicon)[kamermans](/maintainers/kamermans)

---

Top Contributors

[![kamermans](https://avatars.githubusercontent.com/u/266265?v=4)](https://github.com/kamermans "kamermans (11 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

Guzzleprovideroauthoauth2subscriberguzzle4

### Embed Badge

![Health badge](/badges/kamermans-guzzle4-oauth2-subscriber/health.svg)

```
[![Health](https://phpackages.com/badges/kamermans-guzzle4-oauth2-subscriber/health.svg)](https://phpackages.com/packages/kamermans-guzzle4-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)
