All threads / Login with Multiple OAuth Providers using Omniauth Discussion

Ask A Question


You’re not receiving notifications from this thread.

Login with Multiple OAuth Providers using Omniauth Discussion

Alex Musayev ·

I never thought it is possible to authenticate with social media account before email validation.

I've been doing automated merging of social media accounts with the user profile in my app, if email addresses are matching. E.g. if a user signs up as [email protected], and then someone else signs in using Twitter OAuth provider, using Twitter account with the same email, Twitter identity will be merged with the application profile.

Now I need to fix the related use case.

I think most services confirm your email, but I don't know for sure if they force you to do that before using OAuth. It's definitely something to think about. Automatic merging is probably okay so long as you can trust that those accounts were already confirmed. I'm just not 100% that they are. I would guess that every service is different so it's probably safest not to auto-merge. If you find out more details on that, let us know!


Hi Chris Oliver,
I keep getting the following error "You cannot call create unless the parent is saved" on line 25 of the omniauth_callbacks_controller.rb

Was this working correctly with yours?

Dan Frenette ·

So that error is a result of calling create on your service instance when the user it's associated to hasn't been saved to the database. I resolved this by creating by calling find_or_initalize_by on the user model, checking if that record was valid, and then calling save! on the record.

Lauro Silva ·

Hey Dan! I'm having the same problem. The service instance are not being saved. How did you call find_or_initalize_by on the user model? I'm having a hard time implementing it.

Hi, i have the same problem and being stuck for a while now.

Make sure your User validations are passing. We only validate the email and password in this example so if you've required other fields, your User won't be saved.

Okay, found the issue. It failed as Twitter don't give you a user e-mail so it fails on the validation of that one. So i just took care of that case and now it's working but maybe you can review this in one of the episodes how to handle these cases. Especially with the GDPR where a confirmed E-Mail is required.

I am stuck with this issue. Newbie like me + outdated materials = no idea what I am doing :)
I tried to but that didn't let me to login via GitHub. Should I try to solve this issue from devise side or omniauth? Thanks


Hello Chris,

First off thank you kindly for this tutorial, it helped me a lot with my school project.

Now, down to business.

I have integrated the authentication and devise which all works like a charm.

So heres my new issue:: i want t make a post on my app and send it to multiple services and save it to my databse.

i have a Post model, which creates a post on my app and saves to database, but i want to take that post and broadcast it to twitter(and eventually facebook)

do i put the mehtod in the service model under the twitter method? seems like the likely candidate, but a little confused as goRails episode 33 uses it in the User model, which we have on this guide as the omniauth callback controller.

then i was thinking of using boolean logic to check if user.service.provider == twitter run the post_to_twitter method.

any feedback would be great :)

Hi Alex, I think twitter doesnt have the email from the auth_hash, so im getting an error . How do i get around this?
I have since been able to fix this issue, i had to manually request user email from my twitter application settings..

@service = Service.where(provider: auth.provider, uid: auth.uid).first

FYI, that line gives an error if you cancel the omniauth login process.


hello, do u have any tutorials that use react to display the frontend instead of using rails views

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.