The twitter sign in module works on my local and staging server on HTTP fine. But when I install the same module in production mode which is https://example.com, it stops working. The error says “Invalid Twitter OAuth request”. I debugged the code a little bit, and I could understand that the session variables stored in token before redirecting to twitter are lost when control is redirected to my site in twitter/oauth path.
/** * Submit handler for Twitter signin. */ function twitter_signin_redirect() { module_load_include('inc', 'twitter'); $key = variable_get('twitter_consumer_key', ''); $secret = variable_get('twitter_consumer_secret', ''); $twitter = new Twitter($key, $secret); $token = $twitter->get_request_token(); $_SESSION['twitter_oauth']['token'] = $token; $_SESSION['twitter_oauth']['destination'] = $_SERVER['HTTP_REFERER']; $_SESSION['twitter_oauth']['signin'] = TRUE; watchdog("twitter_sign_in", "Session Values Set => ". print_r($_SESSION, 1)); drupal_goto($twitter->get_authenticate_url($token)); }
And on the validate function in twitter.pages.inc, the session values are clearly lost. I used watchdog entries on both functions. Its working fine in my local and staging server.
/** * Validate results from Twitter OAuth return request. */ function twitter_oauth_callback_form_validate($form, &$form_state) { global $twitter_token; $key = variable_get('twitter_consumer_key', ''); $secret = variable_get('twitter_consumer_secret', ''); watchdog("twitter_sign_in", "Session Values Set => ". print_r($_SESSION, 1));
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'); }
Any help appreciated. Thanks.