PHPackages                             jwilsson/auto-refresh-oauth2-token-plugin - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. jwilsson/auto-refresh-oauth2-token-plugin

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

jwilsson/auto-refresh-oauth2-token-plugin
=========================================

HTTPlug plugin to automatically refresh expired OAuth2 access tokens.

v3.1.0(2y ago)1386MITPHPPHP ^8.2CI passing

Since Jan 5Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/jwilsson/php-auto-refresh-oauth2-token-plugin)[ Packagist](https://packagist.org/packages/jwilsson/auto-refresh-oauth2-token-plugin)[ RSS](/packages/jwilsson-auto-refresh-oauth2-token-plugin/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (12)Versions (5)Used By (0)

PHP AutoRefreshOAuth2TokenPlugin
================================

[](#php-autorefreshoauth2tokenplugin)

[![Packagist](https://camo.githubusercontent.com/c8d3dc3104d3cd822d0af5a0e9be983dea8c8aef5bc222546189aaf485346cba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a77696c73736f6e2f6175746f2d726566726573682d6f61757468322d746f6b656e2d706c7567696e2e737667)](https://packagist.org/packages/jwilsson/auto-refresh-oauth2-token-plugin)[![build](https://github.com/jwilsson/php-auto-refresh-oauth2-token-plugin/workflows/build/badge.svg)](https://github.com/jwilsson/php-auto-refresh-oauth2-token-plugin/workflows/build/badge.svg)[![Coverage Status](https://camo.githubusercontent.com/393dad0acdb2a5ad10b5696a11559d473723e685aea675f56a2150d283f88f2d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6a77696c73736f6e2f7068702d6175746f2d726566726573682d6f61757468322d746f6b656e2d706c7567696e2f62616467652e7376673f6272616e63683d6d61696e)](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
------------

[](#requirements)

- PHP 8.4 or later.
- [jwilsson/oauth2-client](https://github.com/jwilsson/php-oauth2-client) library.

Installation
------------

[](#installation)

Via Composer:

```
composer require jwilsson/auto-refresh-oauth2-token-plugin
```

Usage
-----

[](#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.

```
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

[](#options)

- `threshold` - Threshold in seconds for how close to the token's expiry time it should be considered expired. Default is 300 (5 minutes).

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance46

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~248 days

Total

4

Last Release

893d ago

Major Versions

v1.0.0 → v2.0.02022-12-13

v2.0.0 → v3.0.02023-12-02

PHP version history (3 changes)v1.0.0PHP ^8.0

v2.0.0PHP ^8.1

v3.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/567607?v=4)[Jonathan Wilsson](/maintainers/jwilsson)[@jwilsson](https://github.com/jwilsson)

---

Top Contributors

[![jwilsson](https://avatars.githubusercontent.com/u/567607?v=4)](https://github.com/jwilsson "jwilsson (17 commits)")

---

Tags

httplugoauth2php

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jwilsson-auto-refresh-oauth2-token-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/jwilsson-auto-refresh-oauth2-token-plugin/health.svg)](https://phpackages.com/packages/jwilsson-auto-refresh-oauth2-token-plugin)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[google/auth

Google Auth Library for PHP

1.4k294.2M217](/packages/google-auth)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28150.5k](/packages/phpro-http-tools)[simplesamlphp/saml2

SAML2 PHP library from SimpleSAMLphp

30418.0M43](/packages/simplesamlphp-saml2)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
