Skip to main content

3rd party integrations using Oauth/omniauth

Rails • Asked by Masud Hossain

When creating a facebook login, you put user = User.from_omniauth(env["omniauth.auth"]) inside sessions_controller.rb , so when a user goes to /auth/facebook it will prompt them to login via facebook. And now the user will automatically have all his data pulled from facebook and it'll create a session based on it.

But what if I want to create an integration (let's say Salesforce for example) with an already logged in user and than pull data from Salesforce?
Where would I put the user = User.from_omniauth(env["omniauth.auth"]) at that point and how can I make sure the 'integration' stays put even after they log off and than log back in ?

I've had some tough time finding guides on this, because most of the guides are for logging in a user and creating a session, not integrating with 3rd parties.


So for anyone logged in already, you can just link them to the authorization path. That will do the redirect and send you back to the Omniauth controller and because you know your user is signed in, you can attach Salesforce to the user instead of creating a new user and attaching it to the new user. It's almost exactly the same process except for that change when the user is already logged in.


So the 'user = User.from_omniauth(env["omniauth.auth"])' will still go in the sessions_controller under create method?

Or does it make more sense to put it under the update method in sessions controller to do the attaching part to the current user logged in


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.