EDIT I am having this issue with chrome i have tested my script in firefox and its working fine
I am using twitterOAuth
api for twitter authentication for my website but when i authorize my twitter app in return to my callback url then it is not able to verify oauth_token
because $_SESSION['oauth_token'] value is changed
Here is my code index.php which generate url for authentication and store session variable
<?php
require 'autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', 'abc');
define('CONSUMER_SECRET', 'abc');
define('OAUTH_CALLBACK', 'http://example.tk/callback.php');
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
session_start();
$_SESSION['oauth_token'] = $request_token['oauth_token'];
echo "From Sessoin ".$_SESSION['oauth_token']."<br>";
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
$url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
echo '<a href="'.$url.'">Login with twitter</a>';
?>
Here is the code of callback url. Here user is redirected after they authorize app for authentication
<?php
session_start();
require 'autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', 'NxEvR3DcegC83BEKWsSqPrBpG');
define('CONSUMER_SECRET', 'hRPggFw6WNYcl8MfdOGb177y3JVwbAoSZEd2tR1HlJXq5jSRmL');
define('OAUTH_CALLBACK', 'http://www.skywebdeveloper.tk/callback.php');
$request_token = [];
$request_token['oauth_token'] = $_SESSION['oauth_token'];
$request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret'];
if (isset($_REQUEST['oauth_token']) && $request_token['oauth_token'] !== $_REQUEST['oauth_token']) {
// Abort! Something is wrong.
echo "From Sessoin ".$_SESSION['oauth_token'];
echo "<br>From Request Method ".$_REQUEST['oauth_token'];
}
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
//$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
//echo $access_token;
?>
I have commented $access_token
for debugging $_SESSION
variable which changes evertime. $access_token is returning error invalid token which is because its not able to verify session variable with data send back