https://github.com/jwilsson/php-auto-refresh-oauth2-token-plugin
HTTPlug plugin to automatically refresh expired OAuth2 access tokens.
https://github.com/jwilsson/php-auto-refresh-oauth2-token-plugin
httplug oauth2 php
Last synced: 3 months ago
JSON representation
HTTPlug plugin to automatically refresh expired OAuth2 access tokens.
- Host: GitHub
- URL: https://github.com/jwilsson/php-auto-refresh-oauth2-token-plugin
- Owner: jwilsson
- License: mit
- Created: 2022-01-05T14:51:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-21T17:51:16.000Z (7 months ago)
- Last Synced: 2025-04-09T05:04:10.483Z (3 months ago)
- Topics: httplug, oauth2, php
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PHP AutoRefreshOAuth2TokenPlugin
[](https://packagist.org/packages/jwilsson/auto-refresh-oauth2-token-plugin)

[](https://coveralls.io/r/jwilsson/php-auto-refresh-oauth2-token-plugin?branch=main)A [HTTPlug plugin](https://docs.php-http.org/en/latest/plugins/introduction.html) to automatically refresh expired OAuth2 access tokens.
## Requirements
* PHP 8.2 or later.
* [jwilsson/oauth2-client](https://github.com/jwilsson/php-oauth2-client) library.## Installation
Via Composer:```sh
composer require jwilsson/auto-refresh-oauth2-token-plugin
```## Usage
This assumes you have an instantiated Refresh Token grant and Token object from the [jwilsson/oauth2-client](https://github.com/jwilsson/php-oauth2-client) library. A full Token object complete with access token, refresh token, and expiry information is expected.```php
use Http\Client\Common\PluginClient;
use JWilsson\AutoRefreshOAuth2TokenPlugin;$autoRefreshOAuth2TokenPlugin = new AutoRefreshOAuth2TokenPlugin(
$token,
$refreshTokenGrant,
$options, // Options for the plugin, see below
$refreshTokenOptions // Additional options to pass to RefreshToken::requestAccessToken()
);$pluginClient = new PluginClient(
$myHttpClient,
[$autoRefreshOAuth2TokenPlugin]
);$response = $pluginClient->sendRequest($myRequest);
// Remember to grab the token object after each call, it might have been updated with new information
$refreshedToken = $autoRefreshOAuth2TokenPlugin->getToken();
```### Options
* `threshold` - Threshold in seconds for how close to the token's expiry time it should be considered expired. Default is 300 (5 minutes).