Skip to content

Commit

Permalink
Updated Twitter provider to support force_login and authorize for acc…
Browse files Browse the repository at this point in the history
…ess to DMs.
  • Loading branch information
F21 committed Dec 31, 2012
1 parent fb60117 commit af0f3cf
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion hybridauth/Hybrid/Providers/Twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ function initialize()

// Provider api end-points
$this->api->api_base_url = "https://api.twitter.com/1/";
$this->api->authorize_url = "https://api.twitter.com/oauth/authenticate";

if ( isset($this->config['authorize']) && $this->config['authorize']){
$this->api->authorize_url = "https://api.twitter.com/oauth/authorize";
}else{
$this->api->authorize_url = "https://api.twitter.com/oauth/authenticate";
}

$this->api->request_token_url = "https://api.twitter.com/oauth/request_token";
$this->api->access_token_url = "https://api.twitter.com/oauth/access_token";

Expand Down Expand Up @@ -54,6 +60,38 @@ function getUserProfile()

return $this->user->profile;
}

/**
* begin login step
*/
function loginBegin()
{
$tokens = $this->api->requestToken( $this->endpoint );

// request tokens as recived from provider
$this->request_tokens_raw = $tokens;

// check the last HTTP status code returned
if ( $this->api->http_code != 200 ){
throw new Exception( "Authentification failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ), 5 );
}

if ( ! isset( $tokens["oauth_token"] ) ){
throw new Exception( "Authentification failed! {$this->providerId} returned an invalid oauth token.", 5 );
}

$this->token( "request_token" , $tokens["oauth_token"] );
$this->token( "request_token_secret", $tokens["oauth_token_secret"] );

if ( isset($this->config['force_login']) && $this->config['force_login']){
# redirect the user to the provider authentication url with force_login
Hybrid_Auth::redirect( $this->api->authorizeUrl( $tokens, array('force_login' => true) ) );
}else{
# redirect the user to the provider authentication url
Hybrid_Auth::redirect( $this->api->authorizeUrl( $tokens ) );
}

}

/**
* load the user contacts
Expand Down

0 comments on commit af0f3cf

Please sign in to comment.