softonic/guzzle-oauth2-middleware

Guzzle middleware with OAuth2 integration

Package info

github.com/softonic/guzzle-oauth2-middleware

pkg:composer/softonic/guzzle-oauth2-middleware

Statistics

Installs: 3 862 922

Dependents: 4

Suggesters: 0

Stars: 10

Open Issues: 4

2.1.2 2025-01-10 10:44 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

Apache-2.0 632853648b5915e8164eebb64175d4ad87d03055

oauth2Guzzlemiddleware

This package is auto-updated.

Last update: 2026-06-10 14:08:35 UTC


README

👁 Latest Version
👁 Software License
👁 Build Status
👁 Coverage Status
👁 Quality Score
👁 Total Downloads
👁 Average time to resolve an issue
👁 Percentage of issues still open

This package provides middleware for guzzle for handling OAuth2 token negotiation and renewal on expiry transparently. It accecpts PHP League's OAuth 2.0 Clients.

Installation

To install, use composer:

composer require softonic/guzzle-oauth2-middleware

Usage

<?php
$options = [
 'clientId' => '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 test suite and a coding style compliance test suite using PHP CS Fixer.

To run the tests, run the following command from the project folder.

$ docker-compose run test

To run interactively using PsySH:

$ docker-compose run psysh

License

The Apache 2.0 license. Please see LICENSE for more information.