oauth2-client/README.md

90 lines
3.3 KiB
Markdown
Raw Normal View History

2013-03-25 16:59:42 +04:00
# OAuth 2.0 Client Library
2013-03-15 15:26:41 +04:00
2014-01-23 07:39:53 +04:00
[![Build Status](https://travis-ci.org/thephpleague/oauth2-client.png?branch=master)](https://travis-ci.org/thephpleague/oauth2-client)
2013-11-18 06:18:23 +04:00
[![Total Downloads](https://poser.pugx.org/league/oauth2-client/downloads.png)](https://packagist.org/packages/league/oauth2-client)
[![Latest Stable Version](https://poser.pugx.org/league/oauth2-client/v/stable.png)](https://packagist.org/packages/league/oauth2-client)
2013-03-25 16:59:42 +04:00
This library makes it stupidly simple to integrate your application with OAuth 2.0 identity providers. It has built in support for:
2013-03-15 15:26:41 +04:00
* Eventbrite
2013-03-25 16:59:42 +04:00
* Facebook
* Github
* Google
* Instagram
* LinkedIn
* Microsoft
2013-11-14 11:40:10 +04:00
* Vkontakte
2013-03-15 15:26:41 +04:00
2013-03-25 16:59:42 +04:00
Adding support for other providers is trivial.
2014-04-24 07:56:53 +04:00
The library requires PHP 5.3+ and is PSR-4 compatible.
2013-03-25 16:59:42 +04:00
## Usage
```php
2013-08-21 02:10:28 +04:00
$provider = new League\OAuth2\Client\Provider\<provider name>(array(
2013-03-25 16:59:42 +04:00
'clientId' => 'XXXXXXXX',
'clientSecret' => 'XXXXXXXX',
'redirectUri' => 'http://your-registered-redirect-uri/'
));
if ( ! isset($_GET['code'])) {
// If we don't have an authorization code then get one
$provider->authorize();
} else {
try {
// Try to get an access token (using the authorization code grant)
$t = $provider->getAccessToken('authorization_code', array('code' => $_GET['code']));
// NOTE: If you are using Eventbrite you will need to add the grant_type parameter (see below)
// $t = $provider->getAccessToken('authorization_code', array('code' => $_GET['code'], 'grant_type' => 'authorization_code'));
2013-03-25 16:59:42 +04:00
try {
// We got an access token, let's now get the user's details
$userDetails = $provider->getUserDetails($t);
foreach ($userDetails as $attribute => $value) {
var_dump($attribute, $value) . PHP_EOL . PHP_EOL;
}
} catch (Exception $e) {
// Failed to get user details
}
} catch (Exception $e) {
// Failed to get access token
}
}
```
### List of built-in identity providers
| Provider | uid | nickname | name | first_name | last_name | email | location | description | imageUrl | urls |
| :------- | :----- | :------- | :----- | :--------- | :-------- | :----- | :------- | :---------- | :------- | :--- |
| **Eventbrite** | string | null | null | null | null | string | null | null | null | null |
2013-03-25 16:59:42 +04:00
| **Facebook** | string | string | string | string | string | string | string | string | string | array (Facebook) |
| **Github** | string | string | string | null | null | string | null | null | null | array (Github, [personal])|
| **Google** | string | string | string | string | string | string | null | null | string | null |
2013-08-21 02:10:28 +04:00
| **Instagram** | string | string | string | null | null | null | null | string | string | null |
| **LinkedIn** | string | null | string | null | null | string | string | string | string | string |
| **Microsoft** | string | null | string | string | string | string | null | null | string | string |
2013-03-15 15:26:41 +04:00
2013-08-21 02:10:28 +04:00
**Notes**: Providers which return URLs sometimes include additional URLs if the user has provided them. These have been wrapped in []
2013-11-18 06:18:44 +04:00
## License
2014-01-23 07:39:53 +04:00
The MIT License (MIT). Please see [License File](https://github.com/thephpleague/oauth2-client/blob/master/LICENSE) for more information.
2013-12-06 01:20:59 +04:00
2014-01-23 07:39:53 +04:00
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/thephpleague/oauth2-client/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
2013-12-06 01:20:59 +04:00