OAuth Callback causes "Page not found" error


#1

Hi,

Everything is working perfectly fine with authenticating via OAuth. I’ve set my placeholder callback URL to http://votd.adjust-media.mooremediasolutions.co.uk/ and if I don’t specify a URL in my Authorization header, everything works. Unfortunately, whenever I pass oauth_callback, the callback URL is never reached. Even setting the callback to the placeholder doesn’t seem to work.

In my PHP code, I have oauth_callback set to be:

rawurlencode(“http://votd.adjust-media.mooremediasolutions.co.uk/”);

Twitter redirects me to https://api.twitter.com/oauth/http%3A%2F%2Fvotd.adjust-media.mooremediasolutions.co.uk%2F?oauth_token=[...]&oauth_verifier=[...] and I receive the “Sorry, that page doesn’t exist!” error.

Thanks,
Warren


#2

It would seem you’re double encoding your OAuth callback value – or your HTTP or OAuth library is – consider not pre-URL encoding the URL and letting your library take care of it for you.


#3

Ahh that’s fixed it, thanks. I was confused by the Twitter documentation. It says “The only unique parameter in this request is oauth_callback, which must be a URL-encoded version of the URL you wish your user to be redirected to when they complete step 2.”, but then later on says that all of the OAuth parameters have to be URL-encoded.

I’ve got it fixed now, thanks!


#4

hi, can you please help me to fix the same problem,

my callback file looks like this: (comment are in Frensh hope it doesn’t matter :slight_smile: )
$isLoggedOnTwitter = false;

if (!empty($_SESSION[‘access_token’]) && !empty($_SESSION[‘access_token’][‘oauth_token’]) && !empty($_SESSION[‘access_token’][‘oauth_token_secret’])) {

// On récupère les tokens, nous sommes identifiés.
$access_token = $_SESSION['access_token'];

/* On créé la connexion avec Twitter en fournissant les tokens d'accès en paramètres.*/
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

/* On récupère les informations sur le compte Twitter du visiteur */
$twitterInfos = $connection->get('account/verify_credentials');
$isLoggedOnTwitter = true;

}
elseif(isset($_REQUEST[‘oauth_token’]) && $_SESSION[‘oauth_token’] === $_REQUEST[‘oauth_token’]) {

// Les tokens d'accès ne sont pas encore stockés, il faut vérifier l'authentification
/* On créé la connexion avec Twitter en fournissant les tokens d'accès en paramètres.*/
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

/* On vérifie les tokens et récupère le token d'accès */
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);

/* On stocke en session les tokens d'accès et on supprime ceux qui ne sont plus utiles. */
$_SESSION['access_token'] = $access_token;
unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);

if (200 == $connection->http_code) {
	$twitterInfos = $connection->get('account/verify_credentials');
	$isLoggedOnTwitter = true;

}
else {
	$isLoggedOnTwitter = false;
}

}
else {
$isLoggedOnTwitter = false;
}