PHPackages                             didiwuliu/oauth2-client - 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. didiwuliu/oauth2-client

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

didiwuliu/oauth2-client
=======================

OAuth 2.0 Client Library

0.3.0(12y ago)028MITPHPPHP &gt;=5.3.0

Since Mar 25Pushed 11y ago2 watchersCompare

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

READMEChangelogDependencies (4)Versions (5)Used By (0)

OAuth 2.0 Client
================

[](#oauth-20-client)

[![Build Status](https://camo.githubusercontent.com/eaeca8483f52ddc347a1e55025b6fd105a150314a6d2f2bfa1e6672b1ba939b1/68747470733a2f2f7472617669732d63692e6f72672f7468657068706c65616775652f6f61757468322d636c69656e742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/thephpleague/oauth2-client)[![Coverage Status](https://camo.githubusercontent.com/309ee2809bd63837255ea88ca5e5269ff978fb1d5d40f76f3b66a9b02a099265/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7468657068706c65616775652f6f61757468322d636c69656e742f62616467652e706e67)](https://coveralls.io/r/thephpleague/oauth2-client)[![Total Downloads](https://camo.githubusercontent.com/24d03ca5af902ee3346bb678ba3bc85512db7375977e7709b874357759bbb4ad/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f6f61757468322d636c69656e742f646f776e6c6f6164732e706e67)](https://packagist.org/packages/league/oauth2-client)[![Latest Stable Version](https://camo.githubusercontent.com/ce3fe6727031b439e8d4b8e06205bb03e06fe982507f2afc7eaa2a1fb957a3ff/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f6f61757468322d636c69656e742f762f737461626c652e706e67)](https://packagist.org/packages/league/oauth2-client)

This package makes it stupidly simple to integrate your application with OAuth 2.0 identity providers.

Everyone is used to seeing those "Connect with Facebook/Google/etc" buttons around the Internet and social network integration is an important feature of most web-apps these days. Many of these sites use an Authentication and Authorization standard called OAuth 2.0.

It will work with any OAuth 2.0 provider (be it an OAuth 2.0 Server for your own API or Facebook) and provides support for popular systems out of the box. This package abstracts out some of the subtle but important differences between various providers, handles access tokens and refresh tokens, and allows you easy access to profile information on these other sites.

This package is compliant with [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md), [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) and [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md). If you notice compliance oversights, please send a patch via pull request.

Requirements
------------

[](#requirements)

The following versions of PHP are supported.

- PHP 5.4
- PHP 5.5
- PHP 5.6
- HHVM

Usage
-----

[](#usage)

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new League\OAuth2\Client\Provider\(array(
    'clientId'  =>  'XXXXXXXX',
    'clientSecret'  =>  'XXXXXXXX',
    'redirectUri'   =>  'https://your-registered-redirect-uri/'
));

if ( ! isset($_GET['code'])) {

    // If we don't have an authorization code then get one
    header('Location: '.$provider->getAuthorizationUrl());
    exit;

} else {

	// Try to get an access token (using the authorization code grant)
    $token = $provider->getAccessToken('authorization_code', [
    	'code' => $_GET['code']
    ]);

    // If you are using Eventbrite you will need to add the grant_type parameter (see below)
    $token = $provider->getAccessToken('authorization_code', [
    	'code' => $_GET['code'],
    	'grant_type' => 'authorization_code'
    ]);

    // Optional: Now you have a token you can look up a users profile data
    try {

        // We got an access token, let's now get the user's details
        $userDetails = $provider->getUserDetails($token);

        // Use these details to create a new profile
	    printf('Hello %s!', $userDetails->firstName);

    } catch (Exception $e) {

        // Failed to get user details
        exit('Oh dear...');
    }

    // Use this to interact with an API on the users behalf
    echo $token->accessToken;

    // Use this to get a new access token if the old one expires
    echo $token->refreshToken;

    // Number of seconds until the access token will expire, and need refreshing
    echo $token->expires;
}
```

### Refreshing a Token

[](#refreshing-a-token)

```
$provider = new League\OAuth2\Client\Provider\(array(
    'clientId'  =>  'XXXXXXXX',
    'clientSecret'  =>  'XXXXXXXX',
    'redirectUri'   =>  'https://your-registered-redirect-uri/'
));

$grant = new \League\OAuth2\Client\Grant\RefreshToken();
$token = $provider->getAccessToken($grant, ['refresh_token' => $refreshToken]);
```

### Built-In Providers

[](#built-in-providers)

This package currently has built-in support for:

- Eventbrite
- Facebook
- Github
- Google
- Instagram
- LinkedIn
- Microsoft

These are as many OAuth 2 services as we plan to support officially. Maintaining a wide selection of providers damages our ability to make this package the best it can be, especially as we progress towards v1.0.

### Third-Party Providers

[](#third-party-providers)

If you would like to support other providers, please make them available as a Composer package, then link to them below.

These providers allow integration with other providers not supported by `oauth2-client`. They may require an older version so please help them out with a pull request if you notice this.

- [QQ](https://github.com/tlikai/oauth2-client)
- [Weibo](https://github.com/tlikai/oauth2-client)

### Client Packages

[](#client-packages)

Some developers use this library as a base for their own PHP API wrappers, and that seems like a really great idea. It might make it slightly tricky to integrate their provider with an existing generic "OAuth 2.0 All the Things" login system, but it does make working with them easier.

- [Sniply](https://github.com/younes0/sniply)

Install
-------

[](#install)

Via Composer

```
{
    "require": {
        "league/oauth2-client": "~0.3"
    }
}
```

Testing
-------

[](#testing)

```
$ phpunit
```

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/thephpleague/oauth2-client/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Alex Bilbie](https://github.com/alexbilbie)
- [Ben Corlett](https://github.com/bencorlett)
- [James Mills](https://github.com/jamesmills)
- [Phil Sturgeon](https://github.com/philsturgeon)
- [Tom Anderson](https://github.com/TomHAnderson)
- [All Contributors](https://github.com/thephpleague/oauth2-client/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/thephpleague/oauth2-client/blob/master/LICENSE) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~397 days

Total

2

Last Release

4403d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ed32b3e7f1a84b1624cf4587a3b8f722dc9e82bb2af6778d28a975da2942dde?d=identicon)[yiluxiangbei](/maintainers/yiluxiangbei)

---

Top Contributors

[![alexbilbie](https://avatars.githubusercontent.com/u/77991?v=4)](https://github.com/alexbilbie "alexbilbie (57 commits)")[![zhangchunsheng](https://avatars.githubusercontent.com/u/831839?v=4)](https://github.com/zhangchunsheng "zhangchunsheng (38 commits)")[![bencorlett](https://avatars.githubusercontent.com/u/181919?v=4)](https://github.com/bencorlett "bencorlett (11 commits)")[![jamesmills](https://avatars.githubusercontent.com/u/557096?v=4)](https://github.com/jamesmills "jamesmills (8 commits)")[![TomHAnderson](https://avatars.githubusercontent.com/u/493920?v=4)](https://github.com/TomHAnderson "TomHAnderson (8 commits)")[![msurguy](https://avatars.githubusercontent.com/u/585833?v=4)](https://github.com/msurguy "msurguy (6 commits)")[![dhrrgn](https://avatars.githubusercontent.com/u/149921?v=4)](https://github.com/dhrrgn "dhrrgn (3 commits)")[![kornrunner](https://avatars.githubusercontent.com/u/725986?v=4)](https://github.com/kornrunner "kornrunner (2 commits)")[![robertpitt](https://avatars.githubusercontent.com/u/567579?v=4)](https://github.com/robertpitt "robertpitt (2 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (1 commits)")[![cyk](https://avatars.githubusercontent.com/u/423755?v=4)](https://github.com/cyk "cyk (1 commits)")[![benjisg](https://avatars.githubusercontent.com/u/308887?v=4)](https://github.com/benjisg "benjisg (1 commits)")[![PavloPoliakov](https://avatars.githubusercontent.com/u/839290?v=4)](https://github.com/PavloPoliakov "PavloPoliakov (1 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")[![sdh100shaun](https://avatars.githubusercontent.com/u/79883?v=4)](https://github.com/sdh100shaun "sdh100shaun (1 commits)")[![suwardany](https://avatars.githubusercontent.com/u/2053770?v=4)](https://github.com/suwardany "suwardany (1 commits)")[![tfountain](https://avatars.githubusercontent.com/u/387569?v=4)](https://github.com/tfountain "tfountain (1 commits)")[![tlikai](https://avatars.githubusercontent.com/u/1356974?v=4)](https://github.com/tlikai "tlikai (1 commits)")[![bitinn](https://avatars.githubusercontent.com/u/1484279?v=4)](https://github.com/bitinn "bitinn (1 commits)")[![tomsobpl](https://avatars.githubusercontent.com/u/124267?v=4)](https://github.com/tomsobpl "tomsobpl (1 commits)")

---

Tags

AuthenticationSSOidentityoauthoauth2authorizationidpsingle sign on

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/didiwuliu-oauth2-client/health.svg)

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

###  Alternatives

[adam-paterson/oauth2-slack

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

22694.8k5](/packages/adam-paterson-oauth2-slack)

PHPackages © 2026

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