-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hybridauth
committed
Jan 20, 2013
1 parent
a735d5e
commit bef984a
Showing
51 changed files
with
3,909 additions
and
2,450 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,237 +1,31 @@ | ||
<?php | ||
//!! planned to be replaced Y! openid by the oauth1 adapter soon | ||
|
||
/*! | ||
* HybridAuth | ||
* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth | ||
* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html | ||
* http://hybridauth.sourceforge.net | https://github.com/hybridauth/hybridauth | ||
* (c) 2009-2011 HybridAuth authors | hybridauth.sourceforge.net/licenses.html | ||
*/ | ||
|
||
/** | ||
* Yahoo OAuth Class | ||
* | ||
* @package HybridAuth providers package | ||
* @author Lukasz Koprowski <azram19@gmail.com> | ||
* @version 0.2 | ||
* @license BSD License | ||
*/ | ||
|
||
/** | ||
* Hybrid_Providers_Yahoo - Yahoo provider adapter based on OAuth1 protocol | ||
*/ | ||
class Hybrid_Providers_Yahoo extends Hybrid_Provider_Model_OAuth1 | ||
* Hybrid_Providers_Yahoo provider adapter based on OAuth1 protocol | ||
* | ||
* http://hybridauth.sourceforge.net/userguide/IDProvider_info_Yahoo.html | ||
*/ | ||
class Hybrid_Providers_Yahoo extends Hybrid_Provider_Model_OpenID | ||
{ | ||
function initialize() | ||
{ | ||
parent::initialize(); | ||
|
||
// Provider api end-points | ||
$this->api->api_base_url = 'http://social.yahooapis.com/v1/'; | ||
$this->api->authorize_url = 'https://api.login.yahoo.com/oauth/v2/request_auth'; | ||
$this->api->request_token_url = 'https://api.login.yahoo.com/oauth/v2/get_request_token'; | ||
$this->api->access_token_url = 'https://api.login.yahoo.com/oauth/v2/get_token'; | ||
} | ||
|
||
function getUserProfile() | ||
{ | ||
$userId = $this->getCurrentUserId(); | ||
|
||
$parameters = array(); | ||
$parameters['format'] = 'json'; | ||
|
||
$response = $this->api->get( 'user/' . $userId . '/profile', $parameters ); | ||
|
||
if ( ! isset( $response->profile ) ){ | ||
throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 ); | ||
} | ||
|
||
$data = $response->profile; | ||
|
||
$this->user->profile->identifier = (property_exists($data,'guid'))?$data->guid:""; | ||
$this->user->profile->firstName = (property_exists($data,'givenName'))?$data->givenName:""; | ||
$this->user->profile->lastName = (property_exists($data,'familyName'))?$data->familyName:""; | ||
$this->user->profile->displayName = (property_exists($data,'nickname'))?trim( $data->nickname ):""; | ||
$this->user->profile->profileURL = (property_exists($data,'profileUrl'))?$data->profileUrl:""; | ||
$this->user->profile->gender = (property_exists($data,'gender'))?$data->gender:""; | ||
|
||
if( $this->user->profile->gender == "F" ){ | ||
$this->user->profile->gender = "female"; | ||
} | ||
|
||
if( $this->user->profile->gender == "M" ){ | ||
$this->user->profile->gender = "male"; | ||
} | ||
|
||
if( isset($data->emails) ){ | ||
$email = ""; | ||
foreach( $data->emails as $v ){ | ||
if( isset($v->primary) && $v->primary ) { | ||
$email = (property_exists($v,'handle'))?$v->handle:""; | ||
|
||
break; | ||
} | ||
} | ||
|
||
$this->user->profile->email = $email; | ||
$this->user->profile->emailVerified = $email; | ||
} | ||
|
||
$this->user->profile->age = (property_exists($data,'displayAge'))?$data->displayAge:""; | ||
$this->user->profile->photoURL = (property_exists($data,'image'))?$data->image->imageUrl:""; | ||
|
||
$this->user->profile->address = (property_exists($data,'location'))?$data->location:""; | ||
$this->user->profile->language = (property_exists($data,'lang'))?$data->lang:""; | ||
|
||
return $this->user->profile; | ||
} | ||
|
||
/** | ||
* load the user contacts | ||
*/ | ||
function getUserContacts() | ||
{ | ||
$userId = $this->getCurrentUserId(); | ||
|
||
$parameters = array(); | ||
$parameters['format'] = 'json'; | ||
$parameters['count'] = 'max'; | ||
|
||
$response = $this->api->get('user/' . $userId . '/contacts', $parameters); | ||
|
||
if ( $this->api->http_code != 200 ) | ||
{ | ||
throw new Exception( 'User contacts request failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) ); | ||
} | ||
|
||
if ( !$response->contacts->contact && ( $response->errcode != 0 ) ) | ||
{ | ||
return array(); | ||
} | ||
|
||
$contacts = array(); | ||
|
||
foreach( $response->contacts->contact as $item ) { | ||
$uc = new Hybrid_User_Contact(); | ||
|
||
$uc->identifier = $this->selectGUID( $item ); | ||
$uc->email = $this->selectEmail( $item->fields ); | ||
$uc->displayName = $this->selectName( $item->fields ); | ||
$uc->photoURL = $this->selectPhoto( $item->fields ); | ||
|
||
$contacts[] = $uc; | ||
} | ||
|
||
return $contacts; | ||
} | ||
|
||
/** | ||
* return the user activity stream | ||
*/ | ||
function getUserActivity( $stream ) | ||
{ | ||
$userId = $this->getCurrentUserId(); | ||
|
||
$parameters = array(); | ||
$parameters['format'] = 'json'; | ||
$parameters['count'] = 'max'; | ||
|
||
$response = $this->api->get('user/' . $userId . '/updates', $parameters); | ||
|
||
if( ! $response->updates || $this->api->http_code != 200 ) | ||
{ | ||
throw new Exception( 'User activity request failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) ); | ||
} | ||
|
||
$activities = array(); | ||
|
||
foreach( $response->updates as $item ){ | ||
$ua = new Hybrid_User_Activity(); | ||
|
||
$ua->id = (property_exists($item,'collectionID'))?$item->collectionID:""; | ||
$ua->date = (property_exists($item,'lastUpdated'))?$item->lastUpdated:""; | ||
$ua->text = (property_exists($item,'loc_longForm'))?$item->loc_longForm:""; | ||
|
||
$ua->user->identifier = (property_exists($item,'profile_guid'))?$item->profile_guid:""; | ||
$ua->user->displayName = (property_exists($item,'profile_nickname'))?$item->profile_nickname:""; | ||
$ua->user->profileURL = (property_exists($item,'profile_profileUrl'))?$item->profile_profileUrl:""; | ||
$ua->user->photoURL = (property_exists($item,'profile_displayImage'))?$item->profile_displayImage:""; | ||
|
||
$activities[] = $ua; | ||
} | ||
|
||
if( $stream == "me" ){ | ||
$userId = $this->getCurrentUserId(); | ||
$my_activities = array(); | ||
|
||
foreach( $activities as $a ){ | ||
if( $a->user->identifier == $userId ){ | ||
$my_activities[] = $a; | ||
} | ||
} | ||
|
||
return $my_activities; | ||
} | ||
|
||
return $activities; | ||
} | ||
|
||
//-- | ||
|
||
function select($vs, $t) | ||
{ | ||
foreach( $vs as $v ){ | ||
if( $v->type == $t ) { | ||
return $v; | ||
} | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
function selectGUID( $v ) | ||
{ | ||
return (property_exists($v,'id'))?$v->id:""; | ||
} | ||
|
||
function selectName( $v ) | ||
{ | ||
$s = $this->select($v, 'name'); | ||
|
||
if( ! $s ){ | ||
$s = $this->select($v, 'nickname'); | ||
return ($s)?$s->value:""; | ||
} else { | ||
return ($s)?$s->value->givenName . " " . $s->value->familyName:""; | ||
} | ||
} | ||
|
||
function selectNickame( $v ) | ||
{ | ||
$s = $this->select($v, 'nickname'); | ||
return ($s)?$s:""; | ||
} | ||
|
||
function selectPhoto( $v ) | ||
{ | ||
$s = $this->select($v, 'guid'); | ||
return ($s)?(property_exists($s,'image')):""; | ||
} | ||
|
||
function selectEmail( $v ) | ||
{ | ||
$s = $this->select($v, 'email'); | ||
return ($s)?$s->value:""; | ||
} | ||
|
||
public function getCurrentUserId() | ||
{ | ||
$parameters = array(); | ||
$parameters['format'] = 'json'; | ||
var $openidIdentifier = "https://open.login.yahooapis.com/openid20/www.yahoo.com/xrds"; | ||
|
||
$response = $this->api->get( 'me/guid', $parameters ); | ||
/** | ||
* finish login step | ||
*/ | ||
function loginFinish() | ||
{ | ||
parent::loginFinish(); | ||
|
||
if ( ! isset( $response->guid->value ) ){ | ||
throw new Exception( "User id request failed! {$this->providerId} returned an invalid response." ); | ||
} | ||
$this->user->profile->emailVerified = $this->user->profile->email; | ||
|
||
return $response->guid->value; | ||
} | ||
// restore the user profile | ||
Hybrid_Auth::storage()->set( "hauth_session.{$this->providerId}.user", $this->user ); | ||
} | ||
} |
Oops, something went wrong.