Skip to content

Instantly share code, notes, and snippets.

@tlayh
Last active August 29, 2015 13:56
Show Gist options
  • Save tlayh/9303964 to your computer and use it in GitHub Desktop.
Save tlayh/9303964 to your computer and use it in GitHub Desktop.
Login a user during the callback
/**
* login the user
* should receive the information from twitter/oauth if login was successful
*
* @param string $oauthtoken
* @param string $oauthVerifier
* @return boolean
*/
public function loginUser($oauthtoken, $oauthVerifier) {
try {
// create a new twitterOauth object with the temporary oauth_token and oauth_verifier
$this->twitterOAuth = new TwitterOAuth($this->consumerKey, $this->consumerSecret, $oauthtoken, $oauthVerifier);
// get the real oauth_token and oauth_verififer via curl
$tokenCredentials = $this->twitterOAuth->getAccessToken($oauthVerifier);
// create the new object with the real oauth_token and oauth_secret.
$this->twitterOAuth = new TwitterOAuth(
$this->consumerKey, $this->consumerSecret,
$tokenCredentials['oauth_token'], $tokenCredentials['oauth_token_secret']);
// get some informations about the logged in user and verify that everything worked
$twitterInfo = $this->twitterOAuth->get('account/verify_credentials');
if (isset($twitterInfo->errors)) {
// add some error handling
return FALSE;
}
// do something with the data or store it in a session
return TRUE;
} catch (\Exception $e) {
// do some exception handling
return FALSE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment