PHPackages                             hannesvdvreken/php-oauth - 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. hannesvdvreken/php-oauth

Abandoned → [hannesvdvreken/php-oauth](/?search=hannesvdvreken%2Fphp-oauth)Library[Authentication &amp; Authorization](/categories/authentication)

hannesvdvreken/php-oauth
========================

PHP OAuth services

1.1.0(10y ago)131.3k5[1 issues](https://github.com/hannesvdvreken/php-oauth/issues)MITPHPPHP &gt;=5.4.0

Since Jan 20Pushed 10y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (5)Versions (10)Used By (0)

OAuth service classes with Guzzle (v4 and v5, but not v6)
=========================================================

[](#oauth-service-classes-with-guzzle-v4-and-v5-but-not-v6)

[![Build Status](https://camo.githubusercontent.com/a4a2e53def9c1f0b044307031cd51d99b702471e411f0b52a05e3591f2cc774f/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f68616e6e657376647672656b656e2f7068702d6f617574682e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/hannesvdvreken/php-oauth)[![Latest Stable Version](https://camo.githubusercontent.com/02bc2c01beef29083fe83fbaaef68bee6d69df258aa155ac60590b67adc34203/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616e6e657376647672656b656e2f7068702d6f617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hannesvdvreken/php-oauth)[![Total Downloads](https://camo.githubusercontent.com/496ff5ca374bbdc2c490ece1afa7302c25de1b3bcea5ba1e6a82428df89484bc/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616e6e657376647672656b656e2f7068702d6f617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hannesvdvreken/php-oauth)[![Coverage Status](https://camo.githubusercontent.com/cbf3807545653bd66e74a622f1752b1d0b738221e0bf34c6cb4cfd407badc7ba/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f68616e6e657376647672656b656e2f7068702d6f617574682e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/hannesvdvreken/php-oauth?branch=master)[![License](https://camo.githubusercontent.com/ddac946d7cc036abb1a7c9a189c713869d4260a5a45f2122452105262c9a4f8e/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68616e6e657376647672656b656e2f7068702d6f617574682e7376673f7374796c653d666c61742d737175617265)](#license)

Usage
-----

[](#usage)

Let's dive right in.

### Setup

[](#setup)

```
$service = new OAuth\Services\Github();
```

Some possible configuration can be passed on with the constructor, like so:

```
$redirectUri = 'https://example.com/oauth/callback';

$credentials = array(
    'client_id'     => 'client-id',
    'client_secret' => '****',
);

$scopes = array('user', 'user:email');

$token = array(
    'access_token' => $accessToken;
);

$service = new OAuth\Services\Github($redirectUri, $credentials, $scopes, $token);
```

An alternative way is the following:

```
$service = new OAuth\Services\Github;
$service
    ->setRedirectUri($redirectUri)
    ->setCredentials($credentials)
    ->setScopes($scopes)
    ->setToken($token);
```

The service class also has the following getters:

```
$redirectUri = $service->getRedirectUri();
$credentials = $service->getCredentials();
$scopes      = $service->getScopes();
$token       = $service->getToken();
```

The `GuzzleHttp\Client` underneath can be accessed like so:

```
$service->setClient(new GuzzleHttp\Client);
$service->getClient();
```

### Requesting an API

[](#requesting-an-api)

The internal `GuzzleHttp\Client` can be called by calling the same methods on the service class.

```
$response = $service->get('users/self')->json();
```

or

```
$body = ['status' => 'Tweeted with @hannesvdvreken/php-oauth'];
$status = $twitter->post('statuses/update', compact('body'))->json();
```

The internal Guzzle Client will be called with the right token in the header or GET parameter. All you need to do is load the service class with the correct credentials or tokens from your persistance layer or session.

Laravel 4
---------

[](#laravel-4)

If you're using Laravel 4, feel free to register the contained service provider (`OAuth\Support\ServiceProvider`). Register the `OAuth` class alias for the facade to use the following syntax to get a fully configured service class:

```
$twitter = OAuth::consumer('twitter');
```

To create an empty config file in `app/config/packages` just use the artisan command:

```
php artisan config:publish hannesvdvreken/php-oauth
```

OAuth 1.0a
----------

[](#oauth-10a)

For the OAuth1.0a functionality we internally use the Guzzle [OAuth1 subscriber](https://github.com/guzzle/oauth-subscriber). An example:

```
$twitter = new OAuth\Services\Twitter($redirectUri, $credentials);

// Request token for redirecting the user (store it in session afterwards).
$token = $twitter->requestToken();

// Get the url to which we need to redirect the user.
$url = $twitter->authorizationUrl();

// Redirect the user.
header('Location: '. $url); exit;
```

Or in short, the `authorizationUrl` will call the `requestToken` method, if you haven't done so already:

```
// Get the url to which we need to redirect the user.
$url = $twitter->authorizationUrl();

// Get the requestToken that has been requested.
$token = $twitter->getToken();
// And store it.

// And redirect the user.
header('Location: '. $url); exit;
```

In the callback controller...

```
// Give the stored token back to the service class.
$twitter->setToken($token);

// Exchange the get parameters for an access token.
$token = $twitter->accessToken($oauthToken, $oauthVerifier);

// Do a get request, just like you would do with a Guzzle Client.
$profile = $twitter->get('account/verify_credentials.json')->json();
```

OAuth 2
-------

[](#oauth-2)

The OAuth2 flow is easier.

```
$fb = new OAuth\Services\Facebook();

$url = $fb->authorizationUrl();

header('Location: '. $url);
```

In the callback controller...

```
$fb->accessToken($code);

$profile = $fb->get('me')->json();
```

Supported services
------------------

[](#supported-services)

- Campaign Monitor
- Dropbox
- Facebook
- Foursquare
- GitHub
- Google
- Instagram
- MailChimp
- Twitter (OAuth1.0a)
- Stack Exchange

Guzzle v3
---------

[](#guzzle-v3)

If you want to continue to work with the old versions of this library that leveraged Guzzle v3 (`Guzzle\Http\Client` instead of `GuzzleHttp\Client`) then you might want to install the `0.1.*` releases. Pull request with Guzzle v3 compatibility should be made against the `guzzle3` [branch](https://github.com/hannesvdvreken/php-oauth/tree/guzzle3). Install the latest guzzle v3 version with `0.1.*` or `dev-guzzle3`.

Contributing
------------

[](#contributing)

Feel free to make a pull request. A new service class can be as simple as 22 lines of code. Please try to be as [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)compliant as possible. There's no shame if you misplaced a bracket or so!

### Testing

[](#testing)

After installing the dependencies (`composer install`) you just need to run `phpunit` to run the entire test-suite.

License
-------

[](#license)

[MIT](license)

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 96.1% 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 ~96 days

Recently: every ~161 days

Total

8

Last Release

3816d ago

Major Versions

v0.1.4 → 1.0.02014-12-26

PHP version history (2 changes)v0.1.0PHP &gt;=5.3.0

1.0.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9937cd6d2eff58e99c75bc2d4a53066e7c9cfdec457c798d5d02d37e6947f419?d=identicon)[hannesvdvreken](/maintainers/hannesvdvreken)

---

Top Contributors

[![hannesvdvreken](https://avatars.githubusercontent.com/u/1410358?v=4)](https://github.com/hannesvdvreken "hannesvdvreken (74 commits)")[![neovdr](https://avatars.githubusercontent.com/u/923150?v=4)](https://github.com/neovdr "neovdr (2 commits)")[![tankist](https://avatars.githubusercontent.com/u/454477?v=4)](https://github.com/tankist "tankist (1 commits)")

---

Tags

facebookgoogleoauth2githubtwitterOAuth1.0a

### Embed Badge

![Health badge](/badges/hannesvdvreken-php-oauth/health.svg)

```
[![Health](https://phpackages.com/badges/hannesvdvreken-php-oauth/health.svg)](https://phpackages.com/packages/hannesvdvreken-php-oauth)
```

###  Alternatives

[hwi/oauth-bundle

Support for authenticating users using both OAuth1.0a and OAuth2 in Symfony.

2.4k21.5M67](/packages/hwi-oauth-bundle)[socialconnect/auth

Social Connect Auth Component

568845.4k5](/packages/socialconnect-auth)[and/oauth

Simple and amazing OAuth library with many providers. Just try it out!

4645.2k2](/packages/and-oauth)[fof/oauth

Allow users to log in with GitHub, Facebook, Google, Discord, GitLab, LinkedIn, and more!

50118.7k41](/packages/fof-oauth)

PHPackages © 2026

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