https://github.com/softonic/guzzle-oauth2-middleware
This package provides middleware for guzzle for handling OAuth2 token negotiation and renewal on expiry transparently.
https://github.com/softonic/guzzle-oauth2-middleware
Last synced: 7 months ago
JSON representation
This package provides middleware for guzzle for handling OAuth2 token negotiation and renewal on expiry transparently.
- Host: GitHub
- URL: https://github.com/softonic/guzzle-oauth2-middleware
- Owner: softonic
- License: other
- Created: 2017-08-18T10:37:22.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2025-01-10T10:46:18.000Z (over 1 year ago)
- Last Synced: 2025-09-14T04:58:09.154Z (9 months ago)
- Language: PHP
- Size: 29.3 KB
- Stars: 10
- Watchers: 7
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
Guzzle OAuth2 Middleware
=====
[](https://github.com/softonic/guzzle-oauth2-middleware/releases)
[](LICENSE.md)
[](https://travis-ci.org/softonic/guzzle-oauth2-middleware)
[](https://scrutinizer-ci.com/g/softonic/guzzle-oauth2-middleware/code-structure)
[](https://scrutinizer-ci.com/g/softonic/guzzle-oauth2-middleware)
[](https://packagist.org/packages/softonic/guzzle-oauth2-middleware)
[](http://isitmaintained.com/project/softonic/guzzle-oauth2-middleware "Average time to resolve an issue")
[](http://isitmaintained.com/project/softonic/guzzle-oauth2-middleware "Percentage of issues still open")
This package provides middleware for [guzzle](https://github.com/guzzle/guzzle/) for handling OAuth2 token negotiation and renewal on expiry transparently. It accecpts PHP League's [OAuth 2.0 Clients](https://github.com/thephpleague/oauth2-client).
Installation
-------
To install, use composer:
```
composer require softonic/guzzle-oauth2-middleware
```
Usage
-------
``` php
'myclient',
'clientSecret' => 'mysecret'
];
// Any provider extending League\OAuth2\Client\Provider\AbstractProvider will do
$provider = new Softonic\OAuth2\Client\Provider\Softonic($options);
// Send OAuth2 parameters and use token_options for any other parameters your OAuth2 provider needs
$config = ['grant_type' => 'client_credentials', 'scope' => 'myscope', 'token_options' => ['audience' => 'test_audience']];
// Any implementation of PSR-6 Cache will do
$cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter();
$client = \Softonic\OAuth2\Guzzle\Middleware\ClientBuilder::build(
$provider,
$config,
$cache,
['base_uri' => 'https://foo.bar/']
);
$response = $client->request('POST', 'qux);
```
Testing
-------
`softonic/guzzle-oauth2-middleware` has a [PHPUnit](https://phpunit.de) test suite and a coding style compliance test suite using [PHP CS Fixer](http://cs.sensiolabs.org/).
To run the tests, run the following command from the project folder.
``` bash
$ docker-compose run test
```
To run interactively using [PsySH](http://psysh.org/):
``` bash
$ docker-compose run psysh
```
License
-------
The Apache 2.0 license. Please see [LICENSE](LICENSE) for more information.
[PSR-2]: http://www.php-fig.org/psr/psr-2/
[PSR-4]: http://www.php-fig.org/psr/psr-4/