PHPackages                             bmatovu/oauth-negotiator - 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. bmatovu/oauth-negotiator

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

bmatovu/oauth-negotiator
========================

OAuth2 client token manager.

v2.1.0(4y ago)312.5k↓23.7%[1 issues](https://github.com/mtvbrianking/oauth-negotiator/issues)3MITPHPPHP ^7.2.5 || ^8.0

Since Mar 28Pushed 4y agoCompare

[ Source](https://github.com/mtvbrianking/oauth-negotiator)[ Packagist](https://packagist.org/packages/bmatovu/oauth-negotiator)[ Docs](https://github.com/mtvbrianking/oauth-negotiator)[ RSS](/packages/bmatovu-oauth-negotiator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (11)Used By (3)

OAuth Negotiator.
-----------------

[](#oauth-negotiator)

[![Total Downloads](https://camo.githubusercontent.com/8e15d2638ebed4c05754530105f58745a33e504dac4c220f7ec6bb6ad9cde549/68747470733a2f2f706f7365722e707567782e6f72672f626d61746f76752f6f617574682d6e65676f746961746f722f646f776e6c6f616473)](https://packagist.org/packages/bmatovu/oauth-negotiator)[![Latest Stable Version](https://camo.githubusercontent.com/d46f5fdb41d8f36b603fc54b32ac22500fc1d79f898b8dd237bcb8187711ec56/68747470733a2f2f706f7365722e707567782e6f72672f626d61746f76752f6f617574682d6e65676f746961746f722f762f737461626c65)](https://packagist.org/packages/bmatovu/oauth-negotiator)[![License](https://camo.githubusercontent.com/f8cde09f25ae5f1882c66b7bf6a6d2edf244aa64154396b4add0f1f46d64b810/68747470733a2f2f706f7365722e707567782e6f72672f626d61746f76752f6f617574682d6e65676f746961746f722f6c6963656e7365)](https://github.com/mtvbrianking/oauth-negotiator/blob/master/license.txt)

OAuth negotiator is a PHP Guzzle HTTP v6.x Client [Middleware](http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html) that will help you acquire, and refresh your access tokens automatically per application request to the [OAuth2](https://tools.ietf.org/html/rfc6749) server so you don't have to worry about non-existent or expired access tokens.

This package works by tapping into each request.

- First, checking if the request has an authorization header; if present, proceed to execute the request.
- If the request has no set authorization header, the available access token in storage is then added as the request authorization header.
- If no access token is present in storage, it shall request for a new access token from the OAuth server using the main grant type specified.
- If there's an existing access token in storage, but it's expired, and a refresh token grant was specified, it shall try to refresh the expired access token using the available refresh token.

See [flowchart](flowchart.jpg) for detailed process illustration.

#### Grant types

[](#grant-types)

The package supports four grant types out of box, that is; Client Credentials, Refresh Token, Password, and the Authorization Code grant type\*.

You can implement your own custom grant type by simply implementing the `GrantTypeInterface`.

#### Tokens

[](#tokens)

These are the object mapping to the real life access token you would get from an OAuth Server. They implement the `TokenInterface`.

#### Token storage

[](#token-storage)

The package also defaults to a file based persistent token storage, but you can still implement your custom persistent storage, say a session based token storage by implementing the `TokenRepositoryInterface`.

#### Exceptions

[](#exceptions)

- `TokenNotFoundException` thrown by the token repository whenever in case of an unknown token.
- `TokenRequestException` thrown by grant type on failure to acquire an access token.

**Source code [documentation](https://mtvbrianking.github.io/oauth-negotiator/)**

### [Installation](https://packagist.org/packages/bmatovu/oauth-negotiator)

[](#installation)

The package can be installed via composer.

`composer require bmatovu/oauth-negotiator`

### Usage

[](#usage)

Auto-load the package using composer so that it's available in your application scope.

```
