views:

170

answers:

1

I'm using a few different gems here (Devise, Warden, Warden_Oauth), but I think you could answer this question without necessarily being familiar with them. I'm trying to execute a Twitter Oauth strategy, where the app first looks for a user by an access_token and access_secret, and then if it doesn't find one, it creates a new user. I can't figure out how to create the new user / where in this block I should do it.

  config.warden do |manager|

      manager.oauth(:twitter) do |twitter|
         twitter.consumer_secret = "<secret>"
         twitter.consumer_key  = "<key>"
         twitter.options :site => 'http://twitter.com'
      end

      Warden::OAuth.access_token_user_finder(:twitter) do |access_token|
         User.find_by_access_token_and_access_secret(access_token.token, access_token.secret)
      end

      manager.default_strategies.unshift :twitter_oauth
end

Thanks for your help.

A: 

Never worked with Warden, but from exp with others, I guess it should look like this

Warden::OAuth.access_token_user_finder(:twitter) do |access_token|
   user = User.find_by_access_token_and_access_secret(access_token.token, access_token.secret)
   user ||= User.create(:access_token => access_token.token, :secret => access_token.secret)
   end
end
Thomas R. Koll