2017 © Pedro Peláez
 

library oauth2-reddit

Reddit OAuth2 provider for league/oauth2-client

image

rtheunissen/oauth2-reddit

Reddit OAuth2 provider for league/oauth2-client

  • Sunday, April 23, 2017
  • by rtheunissen
  • Repository
  • 2 Watchers
  • 9 Stars
  • 3,058 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 21 Versions
  • 3 % Grown

The README.md

Reddit OAuth2 Provider

Build Status Scrutinizer Scrutinizer Coverage Latest Version License Join the chat at https://gitter.im/rtheunissen/oauth2-reddit, (*1)

This package provides Reddit integration for thephpleague/oauth2-client., (*2)

Installation

composer require rtheunissen/oauth2-reddit

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

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., (*3)

Have a read through the Reddit OAuth2 Wiki to find out more., (*4)

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., (*5)

$accessToken = $reddit->getAccessToken('authorization_code', [
    'code'  => $code,
    'state' => $state
]);
For scripts intended for personal use, using 'username' and 'password'
$accessToken = $reddit->getAccessToken('password', [
    'username' => $username,
    'password' => $password,
]);
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., (*6)

$accessToken = $reddit->getAccessToken('installed_client', [
    'device_id' => $deviceId,  // 20-30 character ASCII string
]);
For confidential clients (web apps / scripts)
$accessToken = $reddit->getAccessToken('client_credentials');

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., (*7)

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., (*8)

$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

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

Note: The pending v1.0.0 release of thephpleague/oauth2-client will make this easier by providing an authenticated request object which you can adjust for each request., (*10)

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

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

The Versions

23/04 2017

dev-master

9999999-dev

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

23/04 2017

v2.0.2

2.0.2.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

16/02 2017

2.0.1.x-dev

2.0.1.9999999-dev

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

16/02 2017

v2.0.1

2.0.1.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

16/02 2017

2.0.0.x-dev

2.0.0.9999999-dev

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

16/02 2017

v2.0.0

2.0.0.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

11/08 2015

dev-2.0.x-dev

dev-2.0.x-dev

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dylan Pierce
by Rudi Theunissen

12/05 2015

v1.2.3

1.2.3.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

12/05 2015

v1.2.2

1.2.2.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

12/05 2015

1.0.x-dev

1.0.9999999.9999999-dev

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

08/05 2015

v1.2.1

1.2.1.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen

08/05 2015

v1.2.0

1.2.0.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen

07/05 2015

v1.1.0

1.1.0.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen

07/05 2015

v1.0.1

1.0.1.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen

07/05 2015

v1.0.0

1.0.0.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen

07/05 2015

v0.1.0

0.1.0.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen

07/05 2015

v0.0.5

0.0.5.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen

07/05 2015

v0.0.4

0.0.4.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen

07/05 2015

v0.0.3

0.0.3.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen

07/05 2015

v0.0.2

0.0.2.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen

07/05 2015

v0.0.1

0.0.1.0

Reddit OAuth2 provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

by Rudi Theunissen