Session being lost before TwitterOauth callback

I’m building something like a multi-twitter-feed-manager, using the
TwitterOauth plugin to handle authorization with Twitter. Before
redirecting to Twitter, I add some data to the session. When Twitter
redirects to the callback, the session is empty. Can anyone explain
this?

Here’s the controller.

class TwitterAuthorizationsController < ApplicationController
def new
@authorization = TwitterAuthorization.new
@authorization.request
@authorization.prepare_session session

#this correctly prints out the session
puts "TwitterAuthorizationsController#new session #

{session.to_json}"

redirect_to @authorization.url

end

def callback
#and here it’s empty
puts “TwitterAuthorizationsController#callback session #
{session.to_json}”

@authorization = TwitterAuthorization.new
@authorization.authorize session

@authorization.save

end
end

And here’s the model:

class TwitterAuthorization < ActiveRecord::Base
has_many :twitter_authentications

def initialize
@client = TwitterOAuth::Client.new(:consumer_key =>
‘****’,:consumer_secret => '’)
end

def request
@request_token = @client.request_token(:oauth_callback => ‘http://
0.0.0.0:3000/oauth_callback’)
end

def authorize session
puts “DEBUG session #{session.to_json}”
@access_token = @client.authorize(
session[:request_token],
session[:request_token_secret],
:oauth_verifier => params
[:oauth_verifier])
if @client.authorized?
access_token = @access_token.token
secret_token = @access_token.secret
end
end

def prepare_session session
session[:request_token] = @request_token.token
session[:request_token_secret] = @request_token.secret
end

def url
@request_token.authorize_url
end
end

Thanks!

-Andrew

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs