Rails Authentication with OAuth 2.0 and OmniAuth

Yeah, I used ENV to hide my keys.

  1. If you use HTTP DELETE, then your link should be something like <%= link_to 'logout', '/logout', method: :delete %>. jquery_ujs adapter should be present on the page for this work, JS should be enabled in the browser.
  2. Have no idea what this means, maybe google can help :smile:
  3. Hrm, thatā€™s interesting, I believe there should be away to test things our using private IP
  4. LinkedIn is the most painful I believe, so good luck :smile:

I have seen discussions pf problems with Facebook not sending an email address unless the account had permissions set to allow it.

Might that be the issue here?

No Mittineageue the problem was, while pasting I had left an inverted comma. So rails treated the app id as wrong. Now I can login with both FB and Twitter.

Hey bodrovis, are you sure the logout does work exactly as expected? Because these, people, have same problem. But Iā€™m one step near to solving it. I changed the code to

`if current_user
   session.delete(:user_id) if session[:user_id]
   # flash[:success] = 'See you!'
   redirect_to root_url
 end`

by putting redirect_to root_url inside if condition. It showed missing template and I created destroy.html.erb. And I was actually logged out. But when I visit the root_path again (not by clicking back button), I was auto logged in. Whats happening?

Iā€™ve pasted my code here.

Actually Iā€™d love to see the full app to test it out :smile:

Hey Ilya! Nice tut as always. I read/watched all the tuts I could find (including yours, railscats, etc.), but Iā€™m still confused a bit. Pls help me out here. I have a rails app with devise authentication. What Iā€™d like to do is keeping the only devise authentication, but when a user is already signed in w/ devise he/she could connect his social media profiles (twitter, linkedin, angellist) to his basic app profile. Example pic from another app attached: 1. On profile edit page user can connect his/her social media profiles. 2. Once those are connected to the in-app profile the logo will appear on userā€™s show page, so when some other user clicks on his/her profile can go the given userā€™s linkedin/twitter page (on twitter/ on linkedin). 3. If there is no profile pic for the user in my app yet then it will be fetched from twitter and integrated.

My questions:

  • What kinda gems are necessary? I will use twitter gem and linkedin gem to make the code shorter, but do I need omniauth gems in this case?
  • What kinda api should I use here? I guess which one I need for updating the profile pic based on twitter (GET account/verify_credentials), but I donā€™t know what to use for redirecting the other users to the userā€™s twitter page.
  • I know I need to authenticate the user by twitter/linkedin to access their twitter/linkedin info, but in my case does it have to do anything w/ devise or can be totally separated? For instance I use :authenticate_user! in twitterā€™s controller so if a user is logged in to my app then can authorize his/her twitter. So do I need omniauth gem here?

Sry if my questions are not crsytal clear, I couldnā€™t create a mental picture yet how this will come together.

Good day!

  1. You donā€™t need any gems apart from omniauth-twitter, omniauth-linkedin and similar. OAuth providers always return a pretty nice hash of various info, including userā€™s name and avatar. Therefore, you can fetch it from there. Twitter gem is used to perform more advanced stuff like fetching friends, posting tweets on userā€™s behalf etc.
  2. No API is needed, since authentication hash returned by the OAuth provider has all the necessary data
  3. Devise does support other omniauth, but I am not really sure if it is needed here. On the first iteration Iā€™d write everything myself.

Hopefully this helps.

Thanks Ilya! I will try it and will let you know the result!

Ilya, could you tell me, how I can avoid create a session here? All the tuts I found created a new session for twitter, but I guess I donā€™t have to create any. I have to do something with the callback though, but I am not sure what.

Could you contact me directly so that we discuss this issue? http://www.radiant-wind.com/ some channels are listed here.

Sure Ilya. Iā€™ve just sent a mail.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.