Ask A Question


You’re not receiving notifications from this thread.

3rd party integrations using Oauth/omniauth

Masud Hossain asked in Rails

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

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 84,387+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.