function twitter_oauth_callback_form_validate in Twitter 7.6
Same name and namespace in other branches
- 7.3 twitter.pages.inc \twitter_oauth_callback_form_validate()
- 7.4 twitter.pages.inc \twitter_oauth_callback_form_validate()
- 7.5 twitter.pages.inc \twitter_oauth_callback_form_validate()
Validate results from Twitter OAuth return request.
File
- ./
twitter.pages.inc, line 475 - Page callbacks for Twitter module.
Code
function twitter_oauth_callback_form_validate($form, &$form_state) {
$key = variable_get('twitter_consumer_key', '');
$secret = variable_get('twitter_consumer_secret', '');
if (isset($_SESSION['twitter_oauth'])) {
$form_state['twitter_oauth'] = $_SESSION['twitter_oauth'];
unset($_SESSION['twitter_oauth']);
}
else {
form_set_error('oauth_token', 'Invalid Twitter OAuth request');
}
if (isset($form_state['twitter_oauth']['token'])) {
$token = $form_state['twitter_oauth']['token'];
if (!is_array($token) || !$key || !$secret) {
form_set_error('oauth_token', t('Invalid Twitter OAuth request'));
}
if ($token['oauth_token'] != $form_state['values']['oauth_token']) {
form_set_error('oauth_token', t('Invalid OAuth token.'));
}
}
else {
form_set_error('oauth_token', t('Invalid Twitter OAuth request'));
}
module_load_include('inc', 'twitter');
if (!empty($token) && ($twitter = new Twitter($key, $secret, $token['oauth_token'], $token['oauth_token_secret']))) {
//Collect oauth_verifier from url
if ($response = $twitter
->get_access_token($_GET['oauth_verifier'])) {
$form_state['twitter_oauth']['response'] = $response;
}
else {
form_set_error('oauth_token', t('Invalid Twitter OAuth request'));
}
}
else {
form_set_error('oauth_token', t('Invalid Twitter OAuth request'));
}
}