PHPackages                             rtheunissen/oauth2-reddit - 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. rtheunissen/oauth2-reddit

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

rtheunissen/oauth2-reddit
=========================

Reddit OAuth2 provider for league/oauth2-client

v2.0.2(9y ago)12104.8k↓16.3%10[1 PRs](https://github.com/rtheunissen/oauth2-reddit/pulls)4MITPHPPHP &gt;=5.6.0

Since May 7Pushed 3y ago2 watchersCompare

[ Source](https://github.com/rtheunissen/oauth2-reddit)[ Packagist](https://packagist.org/packages/rtheunissen/oauth2-reddit)[ RSS](/packages/rtheunissen-oauth2-reddit/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (21)Used By (4)

Reddit OAuth2 Provider
======================

[](#reddit-oauth2-provider)

[![Build Status](https://camo.githubusercontent.com/da0ad52e47f317dd5711ffaa74d00d60bf22e20efe34a5ef0f785266ca3a60c4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f72746865756e697373656e2f6f61757468322d7265646469742e7376673f7374796c653d666c61742d737175617265266272616e63683d6d6173746572)](https://travis-ci.org/rtheunissen/oauth2-reddit)![Scrutinizer](https://camo.githubusercontent.com/79ebbf40e37d4be2bacfb53ffc0267a736143a63d49e12ce034ab13f15a0792f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f72746865756e697373656e2f6f61757468322d7265646469742e7376673f7374796c653d666c61742d737175617265)![Scrutinizer Coverage](https://camo.githubusercontent.com/31d1a87e38bfe81cdceaec8bdfc07857210e26f75d182692f248da5670e84bf5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f72746865756e697373656e2f6f61757468322d7265646469742e7376673f7374796c653d666c61742d737175617265)[![Latest Version](https://camo.githubusercontent.com/b8e467b669c0a8d1fca11286beb17ebad7cc00ba1816907c35c3fae419c39e42/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72746865756e697373656e2f6f61757468322d7265646469742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rtheunissen/oauth2-reddit)[![License](https://camo.githubusercontent.com/241e324d81218150a7e6df963d0898bef789482af3f4d3a33fdc0e3a258b1198/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72746865756e697373656e2f6f61757468322d7265646469742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rtheunissen/oauth2-reddit)[![Join the chat at https://gitter.im/rtheunissen/oauth2-reddit](https://camo.githubusercontent.com/17500808919542378209467f81c4c337ec78de3e9efcc8f8cd20b5be2b89de2b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769747465722d6a6f696e253230636861742532302545322538362539322d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://gitter.im/rtheunissen/oauth2-reddit)

This package provides Reddit integration for [thephpleague/oauth2-client](https://github.com/thephpleague/oauth2-client).

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

[](#installation)

```
composer require rtheunissen/oauth2-reddit
```

Usage
-----

[](#usage)

```
use Rudolf\OAuth2\Client\Provider\Reddit;

$reddit = new Reddit([
    'clientId'      => 'yourClientId',
    'clientSecret'  => 'yourClientSecret',
    'redirectUri'   => 'yourRedirectUri',
    'userAgent'     => 'platform:appid:version, (by /u/username)',
    'scopes'        => ['identity', 'read', ...],
]);
```

#### Requesting an access token

[](#requesting-an-access-token)

There are four different ways to request an access token, and you should be able to determine which to use based on the nature of your application.

Have a read through the [Reddit OAuth2 Wiki](https://github.com/reddit/reddit/wiki/OAuth2) to find out more.

##### For web apps, using 'code' and 'state'

[](#for-web-apps-using-code-and-state)

```
$url = $reddit->getAuthorizationUrl([
    'duration' => $duration,  // "permanent" or "temporary" by default
]);
```

You'll receive both `code` and `state` when redirected from Reddit.

```
$accessToken = $reddit->getAccessToken('authorization_code', [
    'code'  => $code,
    'state' => $state
]);
```

##### For scripts intended for personal use, using 'username' and 'password'

[](#for-scripts-intended-for-personal-use-using-username-and-password)

```
$accessToken = $reddit->getAccessToken('password', [
    'username' => $username,
    'password' => $password,
]);
```

##### For installed applications

[](#for-installed-applications)

> You should generate and save unique ID on your client. The ID should be unique **per-device** or **per-user** of your app. A randomized or pseudo-randomized value is acceptable for generating the ID; however, you should retain and re-use the same device\_id when renewing your access token.

```
$accessToken = $reddit->getAccessToken('installed_client', [
    'device_id' => $deviceId,  // 20-30 character ASCII string
]);
```

##### For confidential clients (web apps / scripts)

[](#for-confidential-clients-web-apps--scripts)

```
$accessToken = $reddit->getAccessToken('client_credentials');
```

#### Refreshing an access token

[](#refreshing-an-access-token)

The only way to get a refresh token is by using the state and code redirect flow, with the duration set as "permanent". The resulting access token will have a valid `refreshToken` property, which you can use to refresh the token.

Note that the refreshed token won't have a `refreshToken` field. You should use the same refresh token every time you refresh the current token, and simply update its `accessToken` and `expires` properties.

```
$refreshToken = $reddit->getAccessToken('refresh_token', [
    'refresh_token' => $accessToken->refreshToken
]);

$accessToken->accessToken = $refreshToken->accessToken;
$accessToken->expires = $refreshToken->expires;

// Remember to re-store the refreshed access token at this point
```

#### Using the access token

[](#using-the-access-token)

Reddit requires a few authorization headers when making authenticated API requests. These can be accessed using `$reddit->getHeaders($token)`.

Note: The pending v1.0.0 release of [thephpleague/oauth2-client](https://github.com/thephpleague/oauth2-client/1.0)will make this easier by providing an authenticated request object which you can adjust for each request.

Until then, you are advised to use either a dedicated HTTP client or the client used by the provider:

```
$client = $reddit->getHttpClient(); // Guzzle 3
```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 95.7% 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 ~40 days

Recently: every ~17 days

Total

19

Last Release

3312d ago

Major Versions

v0.1.0 → v1.0.02015-05-07

v1.2.3 → 2.0.0.x-dev2017-02-16

PHP version history (2 changes)v0.0.1PHP &gt;=5.4.0

2.0.0.x-devPHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/761df764fa80c32031884a5dd2376cf7e70c0fa152eaa141fd68f12b4a761b9f?d=identicon)[rtheunissen](/maintainers/rtheunissen)

---

Top Contributors

[![rtheunissen](https://avatars.githubusercontent.com/u/809191?v=4)](https://github.com/rtheunissen "rtheunissen (44 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![skillfish](https://avatars.githubusercontent.com/u/13037443?v=4)](https://github.com/skillfish "skillfish (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rtheunissen-oauth2-reddit/health.svg)

```
[![Health](https://phpackages.com/badges/rtheunissen-oauth2-reddit/health.svg)](https://phpackages.com/packages/rtheunissen-oauth2-reddit)
```

###  Alternatives

[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

42121.2M118](/packages/league-oauth2-google)[knpuniversity/oauth2-client-bundle

Integration with league/oauth2-client to provide services

84016.7M61](/packages/knpuniversity-oauth2-client-bundle)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2509.6M48](/packages/thenetworg-oauth2-azure)[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[microsoft/kiota-authentication-phpleague

Authentication provider for Kiota using the PHP League OAuth 2.0 client to authenticate against the Microsoft Identity platform

153.2M7](/packages/microsoft-kiota-authentication-phpleague)

PHPackages © 2026

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