Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Facebook->getAccessTokenFromCode() raised no error when IP was not white-listed #54

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
103 changes: 54 additions & 49 deletions hybridauth/Hybrid/Providers/LinkedIn.php 100644 → 100755
Expand Up @@ -2,7 +2,7 @@
/*!
* HybridAuth
* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
*/

/**
Expand All @@ -15,46 +15,46 @@
class Hybrid_Providers_LinkedIn extends Hybrid_Provider_Model
{
/**
* IDp wrappers initializer
* IDp wrappers initializer
*/
function initialize()
function initialize()
{
if ( ! $this->config["keys"]["key"] || ! $this->config["keys"]["secret"] ){
throw new Exception( "Your application key and secret are required in order to connect to {$this->providerId}.", 4 );
}
}

require_once Hybrid_Auth::$config["path_libraries"] . "OAuth/OAuth.php";
require_once Hybrid_Auth::$config["path_libraries"] . "LinkedIn/LinkedIn.php";
$this->api = new LinkedIn( array( 'appKey' => $this->config["keys"]["key"], 'appSecret' => $this->config["keys"]["secret"], 'callbackUrl' => $this->endpoint ) );
require_once Hybrid_Auth::$config["path_libraries"] . "LinkedIn/LinkedIn.php";

$this->api = new LinkedIn( array( 'appKey' => $this->config["keys"]["key"], 'appSecret' => $this->config["keys"]["secret"], 'callbackUrl' => $this->endpoint ) );

if( $this->token( "access_token_linkedin" ) ){
$this->api->setTokenAccess( $this->token( "access_token_linkedin" ) );
}
}

/**
* begin login step
* begin login step
*/
function loginBegin()
{
// send a request for a LinkedIn access token
$response = $this->api->retrieveTokenRequest();
// send a request for a LinkedIn access token
$response = $this->api->retrieveTokenRequest();

if( isset( $response['success'] ) && $response['success'] === TRUE ){
$this->token( "oauth_token", $response['linkedin']['oauth_token'] );
$this->token( "oauth_token_secret", $response['linkedin']['oauth_token_secret'] );
if( isset( $response['success'] ) && $response['success'] === TRUE ){
$this->token( "oauth_token", $response['linkedin']['oauth_token'] );
$this->token( "oauth_token_secret", $response['linkedin']['oauth_token_secret'] );

# redirect user to LinkedIn authorisation web page
Hybrid_Auth::redirect( LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token'] );
}
}
else{
throw new Exception( "Authentification failed! {$this->providerId} returned an invalid Token.", 5 );
}
}
}

/**
* finish login step
* finish login step
*/
function loginFinish()
{
Expand All @@ -67,20 +67,20 @@ function loginFinish()

$response = $this->api->retrieveTokenAccess( $oauth_token, $this->token( "oauth_token_secret" ), $oauth_verifier );

if( isset( $response['success'] ) && $response['success'] === TRUE ){
if( isset( $response['success'] ) && $response['success'] === TRUE ){
$this->deleteToken( "oauth_token" );
$this->deleteToken( "oauth_token_secret" );

$this->token( "access_token_linkedin", $response['linkedin'] );
$this->token( "access_token" , $response['linkedin']['oauth_token'] );
$this->token( "access_token_secret" , $response['linkedin']['oauth_token_secret'] );
$this->token( "access_token_linkedin", $response['linkedin'] );
$this->token( "access_token" , $response['linkedin']['oauth_token'] );
$this->token( "access_token_secret" , $response['linkedin']['oauth_token_secret'] );

// set user as logged in
$this->setUserConnected();
}
}
else{
throw new Exception( "Authentification failed! {$this->providerId} returned an invalid Token.", 5 );
}
}
}

/**
Expand All @@ -97,45 +97,50 @@ function getUserProfile()
}

if( isset( $response['success'] ) && $response['success'] === TRUE ){
$data = @ new SimpleXMLElement( $response['linkedin'] );
$data = @ new SimpleXMLElement( $response['linkedin'] );

if ( ! is_object( $data ) ){
throw new Exception( "User profile request failed! {$this->providerId} returned an invalide xml data.", 6 );
}
}

$this->user->profile->identifier = (string) $data->{'id'};
$this->user->profile->firstName = (string) $data->{'first-name'};
$this->user->profile->lastName = (string) $data->{'last-name'};
$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->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'};
$this->user->profile->photoURL = (string) $data->{'picture-url'};
$this->user->profile->profileURL = (string) $data->{'public-profile-url'};
$this->user->profile->description = (string) $data->{'summary'};

$this->user->profile->phone = (string) $data->{'phone-numbers'}->{'phone-number'}->{'phone-number'};
if( $data->{'phone-numbers'} && $data->{'phone-numbers'}->{'phone-number'} ){
$this->user->profile->phone = (string) $data->{'phone-numbers'}->{'phone-number'}->{'phone-number'};
}
else{
$this->user->profile->phone = null;
}

if( $data->{'date-of-birth'} ) {
$this->user->profile->birthDay = (string) $data->{'date-of-birth'}->day;
$this->user->profile->birthMonth = (string) $data->{'date-of-birth'}->month;
$this->user->profile->birthYear = (string) $data->{'date-of-birth'}->year;
}
if( $data->{'date-of-birth'} ){
$this->user->profile->birthDay = (string) $data->{'date-of-birth'}->day;
$this->user->profile->birthMonth = (string) $data->{'date-of-birth'}->month;
$this->user->profile->birthYear = (string) $data->{'date-of-birth'}->year;
}

return $this->user->profile;
}
else{
throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
}
}
}

/**
* load the user contacts
*/
function getUserContacts()
{
try{
try{
$response = $this->api->profile('~/connections:(id,first-name,last-name,picture-url,public-profile-url,summary)');
}
catch( LinkedInException $e ){
Expand All @@ -146,7 +151,7 @@ function getUserContacts()
return ARRAY();
}

$connections = new SimpleXMLElement( $response['linkedin'] );
$connections = new SimpleXMLElement( $response['linkedin'] );

$contacts = ARRAY();

Expand All @@ -159,7 +164,7 @@ function getUserContacts()
$uc->photoURL = (string) $connection->{'picture-url'};
$uc->description = (string) $connection->{'summary'};

$contacts[] = $uc;
$contacts[] = $uc;
}

return $contacts;
Expand All @@ -178,10 +183,10 @@ function setUserStatus( $status )
if( isset( $status[1] ) && ! empty( $status[1] ) ) $parameters["comment"] = $status[1]; // post comment
if( isset( $status[2] ) && ! empty( $status[2] ) ) $parameters["submitted-url"] = $status[2]; // post url
if( isset( $status[3] ) && ! empty( $status[3] ) ) $parameters["submitted-image-url"] = $status[3]; // post picture url
if( isset( $status[4] ) && ! empty( $status[4] ) ) $private = $status[4]; // true or false
if( isset( $status[4] ) && ! empty( $status[4] ) ) $private = $status[4]; // true or false
}
else{
$parameters["comment"] = $status;
$parameters["comment"] = $status;
}

try{
Expand All @@ -198,18 +203,18 @@ function setUserStatus( $status )
}

/**
* load the user latest activity
* load the user latest activity
* - timeline : all the stream
* - me : the user activity only
* - me : the user activity only
*/
function getUserActivity( $stream )
{
try{
try{
if( $stream == "me" ){
$response = $this->api->updates( '?type=SHAR&scope=self&count=25' );
}
$response = $this->api->updates( '?type=SHAR&scope=self&count=25' );
}
else{
$response = $this->api->updates( '?type=SHAR&count=25' );
$response = $this->api->updates( '?type=SHAR&count=25' );
}
}
catch( LinkedInException $e ){
Expand All @@ -224,7 +229,7 @@ function getUserActivity( $stream )

$activities = ARRAY();

foreach( $updates->update as $update ) {
foreach( $updates->update as $update ) {
$person = $update->{'update-content'}->person;
$share = $update->{'update-content'}->person->{'current-share'};

Expand Down
47 changes: 36 additions & 11 deletions hybridauth/Hybrid/thirdparty/Facebook/base_facebook.php 100644 → 100755
Expand Up @@ -724,6 +724,15 @@ protected function getAccessTokenFromCode($code, $redirect_uri = null) {
return false;
}

// Check for errors, which are returned as json data, rather than query-strings.
if (is_string($access_token_response)) {
$json = json_decode($access_token_response, true);

if (is_array($json)) {
$this->throwAPIExceptionIfError($json);
}
}

$response_params = array();
parse_str($access_token_response, $response_params);
if (!isset($response_params['access_token'])) {
Expand Down Expand Up @@ -752,18 +761,30 @@ protected function _restserver($params) {
), true);

// results are returned, errors are thrown
if (is_array($result) && isset($result['error_code'])) {
$this->throwAPIException($result);
}

$this->throwAPIExceptionIfError($result);

if ($params['method'] === 'auth.expireSession' ||
$params['method'] === 'auth.revokeAuthorization') {
$this->destroySession();
}

return $result;
}


/**
* Throws an exception if an error occurred during an oauth call.
*
* @param array $response
*/
protected function throwAPIExceptionIfError($response)
{
if (is_array($response) &&
(isset($response['error_code']) ||
isset($response['error']))) {
$this->throwAPIException($response);
}
}

/**
* Return true if this is video post.
*
Expand Down Expand Up @@ -808,9 +829,7 @@ protected function _graph($path, $method = 'GET', $params = array()) {
), true);

// results are returned, errors are thrown
if (is_array($result) && isset($result['error'])) {
$this->throwAPIException($result);
}
$this->throwAPIExceptionIfError($result);

return $result;
}
Expand All @@ -836,7 +855,11 @@ protected function _oauthRequest($url, $params) {
}
}

return $this->makeRequest($url, $params);
$result = $this->makeRequest($url, $params);

$this->throwAPIExceptionIfError($result);

return $result;
}

/**
Expand Down Expand Up @@ -1277,7 +1300,7 @@ abstract protected function clearAllPersistentData();
* http://developers.facebook.com/roadmap/offline-access-removal/#extend_token
* http://stackoverflow.com/a/9035036/1106794
*/
function extendedAccessToken( $old_access_token )
public function extendedAccessToken( $old_access_token )
{
// Make a OAuth Request.
try {
Expand All @@ -1301,7 +1324,9 @@ function extendedAccessToken( $old_access_token )
if (empty($response)) {
return false;
}


$this->throwAPIExceptionIfError($response);

$response_params = array();

parse_str($response, $response_params);
Expand Down