Reputation: 281
My rails application needs to use Twitter Oauth twice for two different purposes. The first is the typical user sign in. The second is for adding accounts so that tweets can be scheduled in advance. Think about Hootsuite as an example. You can log-in with Facebook as well as connect various Facebook accounts. This requires two separate call backs.
In order to make callbacks with unique functions, I figured I can just make two different applications, each with a separate callback URL.
However, in the omniauth.rb file, there is only one way to connect to the twitter provider.
Rails.application.middleware.use OmniAuth::Builder do
provider :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"]
end
It does not work to repeat like this:
Rails.application.middleware.use OmniAuth::Builder do
provider :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"]
end
Rails.application.middleware.use OmniAuth::Builder do
provider :twitter, ENV["TWITTERUSER_KEY"], ENV["TWITTERUSER_SECRET"]
end
Because there is no way to distinguish which callback to use. I have not found a way to make the provider ':twitter2' for example because it is built into Omniauth.
Has anyone found a solution to use multiple Twitter callbacks in the same application? Happy to see a solution with any Oauth that needs to be used twice for different purposes, for example Facebook, or Google Plus
Thanks!
Upvotes: 4
Views: 317
Reputation: 11
There is a way to do that, by defining a callback path and a name to the provider.
Rails.application.middleware.use OmniAuth::Builder do
provider :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"], callback_path: "/omniauth/twitter1/callback", name: "twitter1"
provider :twitter, ENV["TWITTERUSER_KEY"], ENV["TWITTERUSER_SECRET"], callback_path: "/omniauth/twitter2/callback", name: "twitter2"
end
Then you use the name to call one or the other provider, like www.mywonderfulwebsite.com/omniauth/twitter1
Hope it helps
Upvotes: 1
Reputation: 2926
If you want to use omniauth for both use cases, you probably cannot do this without significant overrides as they will clash. Have you considered using a different twitter gem to do the auth with twitter for the posting of the tweets?
Upvotes: 0