Using two twitter apps with Oauth, so I can have two separate callbacks

In my rails application, I need to use Twitter Oauth twice for two different purposes. The first is a typical user input. The second is to add accounts so that tweets can be scheduled in advance. Think of Hootsuite as an example. You can log in using Facebook, as well as connect to various Facebook accounts. This requires two separate callbacks.

To make callbacks with unique functions, I decided that I could just create two different applications, each of which has a separate callback URL.

However, the omniauth.rb file has 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 will not happen again:

  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 did not find a way to make a provider: twitter2 'for example, because it is built into Omniauth.

Has anyone found a solution to use multiple Twitter callbacks in one application? I am glad to see a solution with any Oauth that needs to be used twice for different purposes, for example Facebook or Google Plus.

Thanks!

+4
source share
2 answers

If you want to use omniauth for both use cases, you probably cannot do this without significant overrides, as they will collide. Have you considered using another twitter gem to log in with Twitter to post tweets?

0
source

There is a way to do this by defining a callback path and a name for 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, for example www.mywonderfulwebsite.com/omniauth/twitter1

Hope this helps

0
source

Source: https://habr.com/ru/post/1485536/


All Articles