Merge pull request #17 from msurguy/master

Added Linkedin and Microsoft to the providers
1.0
Alex Bilbie 2013-08-23 01:40:32 -07:00
commit 32c1d8480a
3 changed files with 88 additions and 0 deletions

View File

@ -5,6 +5,9 @@ This library makes it stupidly simple to integrate your application with OAuth 2
* Facebook
* Github
* Google
* Instagram
* LinkedIn
* Microsoft
Adding support for other providers is trivial.
@ -62,5 +65,7 @@ if ( ! isset($_GET['code'])) {
| **Github** | string | string | string | null | null | string | null | null | null | array (Github, [personal])|
| **Google** | string | string | string | string | string | string | null | null | string | null |
| **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 |
**Notes**: Providers which return URLs sometimes include additional URLs if the user has provided them. These have been wrapped in []

View File

@ -0,0 +1,42 @@
<?php
namespace League\OAuth2\Client\Provider;
class Linkedin extends IdentityProvider
{
public $scopes = array('r_basicprofile r_emailaddress r_contactinfo');
public $responseType = 'json';
public $fields = array('id', 'email-address', 'first-name', 'last-name', 'headline', 'location', 'industry', 'picture-url', 'public-profile-url');
public function urlAuthorize()
{
return 'https://www.linkedin.com/uas/oauth2/authorization';
}
public function urlAccessToken()
{
return 'https://www.linkedin.com/uas/oauth2/accessToken';
}
public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token)
{
return 'https://api.linkedin.com/v1/people/~:('.implode(",", $this->fields).')?format=json&oauth2_access_token='.$token;
}
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
$user = new User;
$user->uid = $response->id;
$user->name = $response->firstName.' '.$response->lastName;
$user->firstName = $response->firstName;
$user->lastName = $response->lastName;
$user->email = isset($response->emailAddress) ? $response->emailAddress : null;
$user->location = isset($response->location->name) ? $response->location->name : null;
$user->description = isset($response->headline) ? $response->headline : null;
$user->imageUrl = $response->pictureUrl;
$user->urls = $response->publicProfileUrl;
return $user;
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace League\OAuth2\Client\Provider;
class Microsoft extends IdentityProvider
{
public $scopes = array('wl.basic', 'wl.emails');
public $responseType = 'json';
public function urlAuthorize()
{
return 'https://oauth.live.com/authorize';
}
public function urlAccessToken()
{
return 'https://oauth.live.com/token';
}
public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token)
{
return 'https://apis.live.net/v5.0/me?access_token='.$token;
}
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
$imageHeaders = get_headers('https://apis.live.net/v5.0/'.$response->id.'/picture', 1);
$user = new User;
$user->uid = $response->id;
$user->name = $response->name;
$user->firstName = $response->first_name;
$user->lastName = $response->last_name;
$user->email = isset($response->emails->preferred) ? $response->emails->preferred : null;
$user->imageUrl = $imageHeaders['Location'];
$user->urls = $response->link.'/cid-'.$response->id;
return $user;
}
}