From 1ac6e1a976dbd7c33540bf4f3be82c79c35194d9 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 2 Dec 2012 04:24:59 -0800 Subject: [PATCH] HybridAuth updated to 2.1.0 --- e107_handlers/hybridauth/Hybrid/Auth.php | 113 ++++---- e107_handlers/hybridauth/Hybrid/Endpoint.php | 41 +-- e107_handlers/hybridauth/Hybrid/Error.php | 4 +- e107_handlers/hybridauth/Hybrid/Logger.php | 4 +- .../hybridauth/Hybrid/Provider_Adapter.php | 10 +- .../hybridauth/Hybrid/Provider_Model.php | 4 +- .../Hybrid/Provider_Model_OAuth1.php | 9 +- .../Hybrid/Provider_Model_OAuth2.php | 9 +- .../Hybrid/Provider_Model_OpenID.php | 6 +- .../hybridauth/Hybrid/Providers/AOL.php | 4 +- .../hybridauth/Hybrid/Providers/Facebook.php | 46 ++-- .../Hybrid/Providers/Foursquare.php | 6 +- .../hybridauth/Hybrid/Providers/Google.php | 22 +- .../hybridauth/Hybrid/Providers/LinkedIn.php | 9 +- .../hybridauth/Hybrid/Providers/Live.php | 163 ++++++------ .../hybridauth/Hybrid/Providers/MySpace.php | 4 +- .../hybridauth/Hybrid/Providers/OpenID.php | 4 +- .../hybridauth/Hybrid/Providers/Twitter.php | 4 +- .../hybridauth/Hybrid/Providers/Yahoo.php | 241 ++++++++++++++++-- e107_handlers/hybridauth/Hybrid/Storage.php | 41 ++- e107_handlers/hybridauth/Hybrid/User.php | 4 +- .../hybridauth/Hybrid/User_Activity.php | 4 +- .../hybridauth/Hybrid/User_Contact.php | 4 +- .../hybridauth/Hybrid/User_Profile.php | 4 +- .../Hybrid/resources/config.php.tpl | 26 +- .../thirdparty/Facebook/base_facebook.php | 47 ++++ .../Hybrid/thirdparty/LinkedIn/LinkedIn.php | 6 +- .../Hybrid/thirdparty/OAuth/OAuth1Client.php | 11 +- .../Hybrid/thirdparty/OAuth/OAuth2Client.php | 36 +-- .../Hybrid/thirdparty/OpenID/LightOpenID.php | 17 +- 30 files changed, 597 insertions(+), 306 deletions(-) diff --git a/e107_handlers/hybridauth/Hybrid/Auth.php b/e107_handlers/hybridauth/Hybrid/Auth.php index 8b4202301..7ca4a0c07 100644 --- a/e107_handlers/hybridauth/Hybrid/Auth.php +++ b/e107_handlers/hybridauth/Hybrid/Auth.php @@ -1,8 +1,8 @@ getSessionData() ); Hybrid_Logger::info( "Hybrid_Auth initialize: check if any error is stored on the endpoint..." ); if( Hybrid_Error::hasError() ){ diff --git a/e107_handlers/hybridauth/Hybrid/Endpoint.php b/e107_handlers/hybridauth/Hybrid/Endpoint.php index 478673b3a..c27193484 100644 --- a/e107_handlers/hybridauth/Hybrid/Endpoint.php +++ b/e107_handlers/hybridauth/Hybrid/Endpoint.php @@ -1,8 +1,8 @@ config( "CONFIG" ) ) { header( "HTTP/1.0 404 Not Found" ); die( "You cannot access this page directly." ); } - Hybrid_Auth::initialize( unserialize( $_SESSION["HA::CONFIG"] ) ); + Hybrid_Auth::initialize( $storage->config( "CONFIG" ) ); } catch ( Exception $e ){ Hybrid_Logger::error( "Endpoint: Error while trying to init Hybrid_Auth" ); header( "HTTP/1.0 404 Not Found" ); - // print_a($_SESSION); - // echo "e=".$e; die( "Oophs. Error!" ); } } diff --git a/e107_handlers/hybridauth/Hybrid/Error.php b/e107_handlers/hybridauth/Hybrid/Error.php index 0f4a1046e..571dfce8a 100644 --- a/e107_handlers/hybridauth/Hybrid/Error.php +++ b/e107_handlers/hybridauth/Hybrid/Error.php @@ -1,8 +1,8 @@ set( "hauth_session.{$this->id}.hauth_endpoint" , $this->params["login_done"] ); Hybrid_Auth::storage()->set( "hauth_session.{$this->id}.id_provider_params" , $this->params ); - // store config to be used by the end point - $_SESSION["HA::CONFIG"] = serialize( Hybrid_Auth::$config ); + // store config to be used by the end point + Hybrid_Auth::storage()->config( "CONFIG", Hybrid_Auth::$config ); // move on - Hybrid_Logger::debug( "Hybrid_Provider_Adapter::login( {$this->id} ), redirect the user to login_start URL.", $this->params ); + Hybrid_Logger::debug( "Hybrid_Provider_Adapter::login( {$this->id} ), redirect the user to login_start URL." ); Hybrid_Auth::redirect( $this->params["login_start"] ); } diff --git a/e107_handlers/hybridauth/Hybrid/Provider_Model.php b/e107_handlers/hybridauth/Hybrid/Provider_Model.php index 2c9134fbe..276b5cffb 100644 --- a/e107_handlers/hybridauth/Hybrid/Provider_Model.php +++ b/e107_handlers/hybridauth/Hybrid/Provider_Model.php @@ -1,8 +1,8 @@ api = new OAuth1Client( $this->config["keys"]["key"], $this->config["keys"]["secret"] ); } + + // Set curl proxy if exist + if( isset( Hybrid_Auth::$config["proxy"] ) ){ + $this->api->curl_proxy = Hybrid_Auth::$config["proxy"]; + } } // -------------------------------------------------------------------- diff --git a/e107_handlers/hybridauth/Hybrid/Provider_Model_OAuth2.php b/e107_handlers/hybridauth/Hybrid/Provider_Model_OAuth2.php index 806787090..5d5eb46db 100644 --- a/e107_handlers/hybridauth/Hybrid/Provider_Model_OAuth2.php +++ b/e107_handlers/hybridauth/Hybrid/Provider_Model_OAuth2.php @@ -1,8 +1,8 @@ api->access_token_expires_in = $this->token( "expires_in" ); $this->api->access_token_expires_at = $this->token( "expires_at" ); } + + // Set curl proxy if exist + if( isset( Hybrid_Auth::$config["proxy"] ) ){ + $this->api->curl_proxy = Hybrid_Auth::$config["proxy"]; + } } // -------------------------------------------------------------------- diff --git a/e107_handlers/hybridauth/Hybrid/Provider_Model_OpenID.php b/e107_handlers/hybridauth/Hybrid/Provider_Model_OpenID.php index b01fce9ef..64405e0fe 100644 --- a/e107_handlers/hybridauth/Hybrid/Provider_Model_OpenID.php +++ b/e107_handlers/hybridauth/Hybrid/Provider_Model_OpenID.php @@ -1,8 +1,8 @@ api = new LightOpenID( parse_url( Hybrid_Auth::$config["base_url"], PHP_URL_HOST) ); + $this->api = new LightOpenID( parse_url( Hybrid_Auth::$config["base_url"], PHP_URL_HOST), Hybrid_Auth::$config["proxy"] ); } // -------------------------------------------------------------------- diff --git a/e107_handlers/hybridauth/Hybrid/Providers/AOL.php b/e107_handlers/hybridauth/Hybrid/Providers/AOL.php index 996d1ca04..f8e7d709c 100644 --- a/e107_handlers/hybridauth/Hybrid/Providers/AOL.php +++ b/e107_handlers/hybridauth/Hybrid/Providers/AOL.php @@ -1,8 +1,8 @@ providerId}.", 4 ); } - // override requested scope - if( isset( $this->config["scope"] ) && ! empty( $this->config["scope"] ) ){ - $this->scope = $this->config["scope"]; - } - - // override requested display - if( isset( $this->config["display"] ) && ! empty( $this->config["display"] ) ){ - $this->display = $this->config["display"]; - } - if ( ! class_exists('FacebookApiException') ) { require_once Hybrid_Auth::$config["path_libraries"] . "Facebook/base_facebook.php"; require_once Hybrid_Auth::$config["path_libraries"] . "Facebook/facebook.php"; @@ -45,6 +33,17 @@ class Hybrid_Providers_Facebook extends Hybrid_Provider_Model $this->api = new Facebook( ARRAY( 'appId' => $this->config["keys"]["id"], 'secret' => $this->config["keys"]["secret"] ) ); + if ( $this->token("access_token") ) { + $access_token = $this->api->extendedAccessToken( $this->token("access_token") ); + + if( $access_token ){ + $this->token("access_token", $access_token ); + $this->api->setAccessToken( $access_token ); + } + + $this->api->setAccessToken( $this->token("access_token") ); + } + $this->api->getUser(); } @@ -55,8 +54,17 @@ class Hybrid_Providers_Facebook extends Hybrid_Provider_Model */ function loginBegin() { + $parameters = array("scope" => $this->scope, "redirect_uri" => $this->endpoint, "display" => "page"); + $optionals = array("scope", "redirect_uri", "display"); + + foreach ($optionals as $parameter){ + if( isset( $this->config[$parameter] ) && ! empty( $this->config[$parameter] ) ){ + $parameters[$parameter] = $this->config[$parameter]; + } + } + // get the login url - $url = $this->api->getLoginUrl( array( 'scope' => $this->scope, 'display' => $this->display, 'redirect_uri' => $this->endpoint ) ); + $url = $this->api->getLoginUrl( $parameters ); // redirect to facebook Hybrid_Auth::redirect( $url ); @@ -80,10 +88,8 @@ class Hybrid_Providers_Facebook extends Hybrid_Provider_Model // set user as logged in $this->setUserConnected(); - // try to detect the access token for facebook - if( isset( $_SESSION["fb_" . $this->api->getAppId() . "_access_token" ] ) ){ - $this->token( "access_token", $_SESSION["fb_" . $this->api->getAppId() . "_access_token" ] ); - } + // store facebook access token + $this->token( "access_token", $this->api->getAccessToken() ); } /** diff --git a/e107_handlers/hybridauth/Hybrid/Providers/Foursquare.php b/e107_handlers/hybridauth/Hybrid/Providers/Foursquare.php index 8df26142f..0ac49bf2c 100644 --- a/e107_handlers/hybridauth/Hybrid/Providers/Foursquare.php +++ b/e107_handlers/hybridauth/Hybrid/Providers/Foursquare.php @@ -1,8 +1,8 @@ user->profile->lastName = $data->lastName; $this->user->profile->displayName = trim( $this->user->profile->firstName . " " . $this->user->profile->lastName ); $this->user->profile->photoURL = $data->photo; - $this->user->profile->profileURL = $data->canonicalUrl; + $this->user->profile->profileURL = "https://www.foursquare.com/user/" . $data->id; $this->user->profile->gender = $data->gender; $this->user->profile->city = $data->homeCity; $this->user->profile->email = $data->contact->email; diff --git a/e107_handlers/hybridauth/Hybrid/Providers/Google.php b/e107_handlers/hybridauth/Hybrid/Providers/Google.php index 424f8f7c4..434cfffc2 100644 --- a/e107_handlers/hybridauth/Hybrid/Providers/Google.php +++ b/e107_handlers/hybridauth/Hybrid/Providers/Google.php @@ -1,8 +1,8 @@ api->authorizeUrl( array( "scope" => $this->scope, "access_type" => "offline" ) ) ); + $parameters = array("scope" => $this->scope, "access_type" => "offline"); + $optionals = array("scope", "access_type", "redirect_uri", "approval_prompt"); + + foreach ($optionals as $parameter){ + if( isset( $this->config[$parameter] ) && ! empty( $this->config[$parameter] ) ){ + $parameters[$parameter] = $this->config[$parameter]; + } + } + + Hybrid_Auth::redirect( $this->api->authorizeUrl( $parameters ) ); } /** @@ -82,7 +91,12 @@ class Hybrid_Providers_Google extends Hybrid_Provider_Model_OAuth2 // refresh tokens if needed $this->refreshToken(); - $response = $this->api->api( "https://www.google.com/m8/feeds/contacts/default/full?alt=json" ); + if( ! isset( $this->config['contacts_param'] ) ){ + $this->config['contacts_param'] = array( "max-results" => 500 ); + } + + $response = $this->api->api( "https://www.google.com/m8/feeds/contacts/default/full?" + . http_build_query( array_merge( array('alt' => 'json'), $this->config['contacts_param'] ) ) ); if( ! $response ){ return ARRAY(); diff --git a/e107_handlers/hybridauth/Hybrid/Providers/LinkedIn.php b/e107_handlers/hybridauth/Hybrid/Providers/LinkedIn.php index 982770ff2..5e755c1f3 100644 --- a/e107_handlers/hybridauth/Hybrid/Providers/LinkedIn.php +++ b/e107_handlers/hybridauth/Hybrid/Providers/LinkedIn.php @@ -1,8 +1,8 @@ api->profile('~:(id,first-name,last-name,public-profile-url,picture-url,date-of-birth,phone-numbers,summary)'); + $response = $this->api->profile('~:(id,first-name,last-name,public-profile-url,picture-url,email-address,date-of-birth,phone-numbers,summary)'); } catch( LinkedInException $e ){ throw new Exception( "User profile request failed! {$this->providerId} returned an error: $e", 6 ); @@ -108,6 +108,9 @@ class Hybrid_Providers_LinkedIn extends Hybrid_Provider_Model $this->user->profile->lastName = (string) $data->{'last-name'}; $this->user->profile->displayName = trim( $this->user->profile->firstName . " " . $this->user->profile->lastName ); + $this->user->profile->email = (string) $data->{'email-address'}; + $this->user->profile->emailVerified = (string) $data->{'email-address'}; + $this->user->profile->photoURL = (string) $data->{'picture-url'}; $this->user->profile->profileURL = (string) $data->{'public-profile-url'}; $this->user->profile->description = (string) $data->{'summary'}; diff --git a/e107_handlers/hybridauth/Hybrid/Providers/Live.php b/e107_handlers/hybridauth/Hybrid/Providers/Live.php index ea1fd1391..a63bbef25 100644 --- a/e107_handlers/hybridauth/Hybrid/Providers/Live.php +++ b/e107_handlers/hybridauth/Hybrid/Providers/Live.php @@ -1,117 +1,106 @@ + * @version 0.2 + * @license BSD License + */ + /** - * Hybrid_Providers_Live provider adapter based on OAuth1 protocol - * - * Hybrid_Providers_Live use OAuthWrapHandler class provided by microsoft - * - * http://hybridauth.sourceforge.net/userguide/IDProvider_info_Live.html + * Hybrid_Providers_Live - Windows Live provider adapter based on OAuth2 protocol */ -class Hybrid_Providers_Live extends Hybrid_Provider_Model +class Hybrid_Providers_Live extends Hybrid_Provider_Model_OAuth2 { + // default permissions + public $scope = "wl.basic wl.emails wl.signin wl.share wl.birthday"; + + /** * IDp wrappers initializer */ function initialize() { - if ( ! $this->config["keys"]["id"] || ! $this->config["keys"]["secret"] ){ - throw new Exception( "Your application id and secret are required in order to connect to {$this->providerId}.", 4 ); - } + parent::initialize(); - // Application Specific Globals - define( 'WRAP_CLIENT_ID' , $this->config["keys"]["id"] ); - define( 'WRAP_CLIENT_SECRET', $this->config["keys"]["secret"] ); - define( 'WRAP_CALLBACK' , $this->endpoint ); - define( 'WRAP_CHANNEL_URL' , Hybrid_Auth::$config["base_url"] . "?get=windows_live_channel" ); + // Provider api end-points + $this->api->api_base_url = "https://apis.live.net/v5.0/"; + $this->api->authorize_url = "https://oauth.live.com/authorize"; + $this->api->token_url = 'https://oauth.live.com/token'; - // Live URLs required for making requests. - define('WRAP_CONSENT_URL' , 'https://consent.live.com/Connect.aspx'); - define('WRAP_ACCESS_URL' , 'https://consent.live.com/AccessToken.aspx'); - define('WRAP_REFRESH_URL' , 'https://consent.live.com/RefreshToken.aspx'); - - require_once Hybrid_Auth::$config["path_libraries"] . "WindowsLive/OAuthWrapHandler.php"; - - $this->api = new OAuthWrapHandler(); + $this->api->curl_authenticate_method = "GET"; } /** - * begin login step - */ - function loginBegin() - { - $this->api->ExpireCookies(); - - Hybrid_Auth::redirect( WRAP_CONSENT_URL . "?wrap_client_id=" . WRAP_CLIENT_ID . "&wrap_callback=" . urlencode( WRAP_CALLBACK ) . "&wrap_scope=WL_Profiles.View" ); - } - - /** - * finish login step - */ - function loginFinish() - { - $response = $this->api->ProcessRequest(); - - if ( ! isset( $response['c_uid'] ) || ! isset( $response['c_accessToken'] ) ){ - throw new Exception( "Authentification failed! {$this->providerId} returned an invalid Token.", 5 ); - } - - // set user as logged in - $this->setUserConnected(); - - # store access token - $this->token( "access_token", $response['c_accessToken'] ); - - # store the user id. - $this->token( "user_id", $response['c_uid'] ); - } - - /** - * load the user profile from the IDp api client + * grab the user profile from the api client */ function getUserProfile() { - try{ - $access_token = $this->token( "access_token" ); + $data = $this->api->get( "me" ); - $user_id = $this->token( "user_id" ); - - $info_url = 'http://apis.live.net/V4.1/cid-'. $user_id .'/Profiles/1-' . $user_id; - - $response = $this->api->GET( $info_url, false, $access_token ); - - $response = json_decode( $response ); - } - catch( Exception $e ){ - throw new Exception( "User profile request failed! {$this->providerId} returned an error while requesting the user profile.", 6 ); + if ( ! isset( $data->id ) ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an invalide response.", 6 ); } - if ( ! is_object( $response ) ){ - throw new Exception( "User profile request failed! {$this->providerId} returned an invalid user data.", 6 ); - } + $this->user->profile->identifier = (property_exists($data,'id'))?$data->id:""; + $this->user->profile->firstName = (property_exists($data,'first_name'))?$data->first_name:""; + $this->user->profile->lastName = (property_exists($data,'last_name'))?$data->last_name:""; + $this->user->profile->displayName = (property_exists($data,'name'))?trim( $data->name ):""; + $this->user->profile->gender = (property_exists($data,'gender'))?$data->gender:""; - $this->user->profile->identifier = $user_id; - $this->user->profile->firstName = (string) $response->FirstName; - $this->user->profile->lastName = (string) $response->LastName; - $this->user->profile->profileURL = (string) $response->UxLink; - $this->user->profile->gender = (string) $response->Gender; - $this->user->profile->email = (string) $response->Emails[0]->Address; - $this->user->profile->displayName = trim( $this->user->profile->firstName . " " . $this->user->profile->lastName ); + //wl.basic + $this->user->profile->profileURL = (property_exists($data,'link'))?$data->link:""; - if( $this->user->profile->gender == 1 ){ - $this->user->profile->gender = "female"; - } - elseif( $this->user->profile->gender == 2 ){ - $this->user->profile->gender = "male"; - } - else{ - $this->user->profile->gender = ""; - } + //wl.emails + $this->user->profile->email = (property_exists($data,'emails'))?$data->emails->account:""; + $this->user->profile->emailVerified = (property_exists($data,'emails'))?$data->emails->account:""; + + //wl.birthday + $this->user->profile->birthDay = (property_exists($data,'birth_day'))?$data->birth_day:""; + $this->user->profile->birthMonth = (property_exists($data,'birth_month'))?$data->birth_month:""; + $this->user->profile->birthYear = (property_exists($data,'birth_year'))?$data->birth_year:""; return $this->user->profile; } + + + /** + * load the current logged in user contacts list from the IDp api client + */ + + /* Windows Live api does not support retrieval of email addresses (only hashes :/) */ + function getUserContacts() + { + $response = $this->api->get( 'me/contacts' ); + + 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->data && ( $response->error != 0 ) ) + { + return array(); + } + + $contacts = array(); + + foreach( $response->data as $item ) { + $uc = new Hybrid_User_Contact(); + + $uc->identifier = (property_exists($item,'id'))?$item->id:""; + $uc->displayName = (property_exists($item,'name'))?$item->name:""; + + $contacts[] = $uc; + } + + return $contacts; + } } diff --git a/e107_handlers/hybridauth/Hybrid/Providers/MySpace.php b/e107_handlers/hybridauth/Hybrid/Providers/MySpace.php index 2d5806874..cf3f6a40b 100644 --- a/e107_handlers/hybridauth/Hybrid/Providers/MySpace.php +++ b/e107_handlers/hybridauth/Hybrid/Providers/MySpace.php @@ -1,8 +1,8 @@ + * @version 0.2 + * @license BSD License + */ + /** -* 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 + * Hybrid_Providers_Yahoo - Yahoo provider adapter based on OAuth1 protocol + */ +class Hybrid_Providers_Yahoo extends Hybrid_Provider_Model_OAuth1 { - var $openidIdentifier = "https://open.login.yahooapis.com/openid20/www.yahoo.com/xrds"; + 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 invalide 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; + } /** - * finish login step - */ - function loginFinish() + * load the user contacts + */ + function getUserContacts() { - parent::loginFinish(); + $userId = $this->getCurrentUserId(); - $this->user->profile->emailVerified = $this->user->profile->email; + $parameters = array(); + $parameters['format'] = 'json'; + $parameters['count'] = 'max'; + + $response = $this->api->get('user/' . $userId . '/contacts', $parameters); - // restore the user profile - Hybrid_Auth::storage()->set( "hauth_session.{$this->providerId}.user", $this->user ); + 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'; + + $response = $this->api->get( 'me/guid', $parameters ); + + if ( ! isset( $response->guid->value ) ){ + throw new Exception( "User id request failed! {$this->providerId} returned an invalide response." ); + } + + return $response->guid->value; } } - diff --git a/e107_handlers/hybridauth/Hybrid/Storage.php b/e107_handlers/hybridauth/Hybrid/Storage.php index cb25a57e9..145863306 100644 --- a/e107_handlers/hybridauth/Hybrid/Storage.php +++ b/e107_handlers/hybridauth/Hybrid/Storage.php @@ -1,8 +1,8 @@ config( "php_session_id", session_id() ); + $this->config( "version", Hybrid_Auth::$version ); } - public function get($key, $expiration = false) + public function config($key, $value=null) + { + $key = strtolower( $key ); + + if( $value ){ + $_SESSION["HA::CONFIG"][$key] = serialize( $value ); + } + elseif( isset( $_SESSION["HA::CONFIG"][$key] ) ){ + return unserialize( $_SESSION["HA::CONFIG"][$key] ); + } + + return NULL; + } + + public function get($key) { $key = strtolower( $key ); @@ -63,12 +82,16 @@ class Hybrid_Storage } function getSessionData() - { - return serialize( $_SESSION["HA::STORE"] ); + { + if( isset( $_SESSION["HA::STORE"] ) ){ + return serialize( $_SESSION["HA::STORE"] ); + } + + return NULL; } function restoreSessionData( $sessiondata = NULL ) { $_SESSION["HA::STORE"] = unserialize( $sessiondata ); - } + } } diff --git a/e107_handlers/hybridauth/Hybrid/User.php b/e107_handlers/hybridauth/Hybrid/User.php index 6187d6d4e..707999aa5 100644 --- a/e107_handlers/hybridauth/Hybrid/User.php +++ b/e107_handlers/hybridauth/Hybrid/User.php @@ -1,8 +1,8 @@ #OPENID_ADAPTER_STATUS# ), - "Yahoo" => array ( - "enabled" => #YAHOO_ADAPTER_STATUS# - ), - "AOL" => array ( "enabled" => #AOL_ADAPTER_STATUS# ), + "Yahoo" => array ( + "enabled" => #YAHOO_ADAPTER_STATUS#, + "keys" => array ( "id" => "#YAHOO_APPLICATION_KEY#", "secret" => "#YAHOO_APPLICATION_SECRET#" ) + ), + "Google" => array ( "enabled" => #GOOGLE_ADAPTER_STATUS#, - "keys" => array ( "id" => "#GOOGLE_APPLICATION_APP_ID#", "secret" => "#GOOGLE_APPLICATION_SECRET#" ), - "scope" => "" + "keys" => array ( "id" => "#GOOGLE_APPLICATION_APP_ID#", "secret" => "#GOOGLE_APPLICATION_SECRET#" ) ), "Facebook" => array ( "enabled" => #FACEBOOK_ADAPTER_STATUS#, - "keys" => array ( "id" => "#FACEBOOK_APPLICATION_APP_ID#", "secret" => "#FACEBOOK_APPLICATION_SECRET#" ), - - // A comma-separated list of permissions you want to request from the user. See the Facebook docs for a full list of available permissions: http://developers.facebook.com/docs/reference/api/permissions. - "scope" => "", - - // The display context to show the authentication page. Options are: page, popup, iframe, touch and wap. Read the Facebook docs for more details: http://developers.facebook.com/docs/reference/dialogs#display. Default: page - "display" => "" + "keys" => array ( "id" => "#FACEBOOK_APPLICATION_APP_ID#", "secret" => "#FACEBOOK_APPLICATION_SECRET#" ) ), "Twitter" => array ( @@ -74,5 +68,5 @@ return // if you want to enable logging, set 'debug_mode' to true then provide a writable file by the web server on "debug_file" "debug_mode" => false, - "debug_file" => "", + "debug_file" => "" ); diff --git a/e107_handlers/hybridauth/Hybrid/thirdparty/Facebook/base_facebook.php b/e107_handlers/hybridauth/Hybrid/thirdparty/Facebook/base_facebook.php index 772cc97e1..5587beee9 100644 --- a/e107_handlers/hybridauth/Hybrid/thirdparty/Facebook/base_facebook.php +++ b/e107_handlers/hybridauth/Hybrid/thirdparty/Facebook/base_facebook.php @@ -1,4 +1,6 @@ $this->getAppId(), + 'client_secret' => $this->getAppSecret(), + 'grant_type' => 'fb_exchange_token', + 'fb_exchange_token' => $old_access_token, + ); + + $response = $this->_oauthRequest( $this->getUrl( 'graph', '/oauth/access_token' ), $params ); + + // print_r( array( $this->getUrl( 'graph', '/oauth/access_token' ), $params, $response ) ); + } + catch ( FacebookApiException $e ) { + // most likely that user very recently revoked authorization. + // In any event, we don't have an access token, so say so. + return false; + } + + if (empty($response)) { + return false; + } + + $response_params = array(); + + parse_str($response, $response_params); + + if (!isset($response_params['access_token'])) { + return false; + } + + return $response_params['access_token']; + } + } diff --git a/e107_handlers/hybridauth/Hybrid/thirdparty/LinkedIn/LinkedIn.php b/e107_handlers/hybridauth/Hybrid/thirdparty/LinkedIn/LinkedIn.php index 59882ba2f..05b8cfe76 100644 --- a/e107_handlers/hybridauth/Hybrid/thirdparty/LinkedIn/LinkedIn.php +++ b/e107_handlers/hybridauth/Hybrid/thirdparty/LinkedIn/LinkedIn.php @@ -1,6 +1,7 @@ \ No newline at end of file +?> diff --git a/e107_handlers/hybridauth/Hybrid/thirdparty/OAuth/OAuth1Client.php b/e107_handlers/hybridauth/Hybrid/thirdparty/OAuth/OAuth1Client.php index 188f18f31..4c6dc52c5 100644 --- a/e107_handlers/hybridauth/Hybrid/thirdparty/OAuth/OAuth1Client.php +++ b/e107_handlers/hybridauth/Hybrid/thirdparty/OAuth/OAuth1Client.php @@ -1,8 +1,8 @@ curl_ssl_verifypeer ); curl_setopt( $ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader') ); curl_setopt( $ci, CURLOPT_HEADER , FALSE ); - + + if($this->curl_proxy){ + curl_setopt( $ci, CURLOPT_PROXY , $this->curl_proxy); + } + switch ($method){ case 'POST': curl_setopt( $ci, CURLOPT_POST, TRUE ); diff --git a/e107_handlers/hybridauth/Hybrid/thirdparty/OAuth/OAuth2Client.php b/e107_handlers/hybridauth/Hybrid/thirdparty/OAuth/OAuth2Client.php index 56afd6dc4..1642faf81 100644 --- a/e107_handlers/hybridauth/Hybrid/thirdparty/OAuth/OAuth2Client.php +++ b/e107_handlers/hybridauth/Hybrid/thirdparty/OAuth/OAuth2Client.php @@ -1,8 +1,8 @@ authorize_url . "?" . http_build_query( $params ); } - public function authenticate( $code ) + public function authenticate( $code ) { $params = array( "client_id" => $this->client_id, @@ -71,8 +73,9 @@ class OAuth2Client "redirect_uri" => $this->redirect_uri, "code" => $code ); - - $response = $this->request( $this->token_url, $params, "POST" ); + + $response = $this->request( $this->token_url, $params, $this->curl_authenticate_method ); + $response = $this->parseRequestResult( $response ); if( ! $response || ! isset( $response->access_token ) ){ @@ -87,7 +90,7 @@ class OAuth2Client $this->access_token_expires_at = time() + $response->expires_in; return $response; - } + } public function authenticated() { @@ -203,13 +206,16 @@ class OAuth2Client curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , $this->curl_ssl_verifypeer ); curl_setopt($ch, CURLOPT_HTTPHEADER , $this->curl_header ); + if($this->curl_proxy){ + curl_setopt( $ch, CURLOPT_PROXY , $this->curl_proxy); + } + if( $type == "POST" ){ curl_setopt($ch, CURLOPT_POST, 1); if($params) curl_setopt( $ch, CURLOPT_POSTFIELDS, $params ); } $response = curl_exec($ch); - Hybrid_Logger::debug( "OAuth2Client::request(). dump request info: ", serialize( curl_getinfo($ch) ) ); Hybrid_Logger::debug( "OAuth2Client::request(). dump request result: ", serialize( $response ) ); diff --git a/e107_handlers/hybridauth/Hybrid/thirdparty/OpenID/LightOpenID.php b/e107_handlers/hybridauth/Hybrid/thirdparty/OpenID/LightOpenID.php index da7cd1545..2bb935c8f 100644 --- a/e107_handlers/hybridauth/Hybrid/thirdparty/OpenID/LightOpenID.php +++ b/e107_handlers/hybridauth/Hybrid/thirdparty/OpenID/LightOpenID.php @@ -21,7 +21,7 @@ class LightOpenID , $data; private $identity, $claimed_id; protected $server, $version, $trustRoot, $aliases, $identifier_select = false - , $ax = false, $sreg = false, $setup_url = null, $headers = array(); + , $ax = false, $sreg = false, $setup_url = null, $headers = array(), $proxy = null; static protected $ax_to_sreg = array( 'namePerson/friendly' => 'nickname', 'contact/email' => 'email', @@ -34,8 +34,9 @@ class LightOpenID 'pref/timezone' => 'timezone', ); - function __construct($host) + function __construct($host, $proxy) { + $this->proxy = $proxy; $this->trustRoot = (strpos($host, '://') ? $host : 'http://' . $host); if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) @@ -126,7 +127,9 @@ class LightOpenID curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/xrds+xml, */*')); - + if($this->proxy){ + curl_setopt( $curl, CURLOPT_PROXY, $this->proxy); + } if($this->verify_peer !== null) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verify_peer); if($this->capath) { @@ -244,6 +247,9 @@ class LightOpenID ), ); $url = $url . ($params ? '?' . $params : ''); + if($this->proxy){ + $opts['http']['proxy'] = 'http://' . $this->proxy; + } break; case 'POST': $opts = array( @@ -256,6 +262,9 @@ class LightOpenID 'CN_match' => parse_url($url, PHP_URL_HOST), ), ); + if($this->proxy){ + $opts['http']['proxy'] = 'http://' . $this->proxy; + } break; case 'HEAD': # We want to send a HEAD request, @@ -312,7 +321,7 @@ class LightOpenID $this->headers = $this->parse_header_array($http_response_header, $update_claimed_id); } - return file_get_contents($url, false, $context); + return $data; } protected function request($url, $method='GET', $params=array(), $update_claimed_id=false)