Skip to main content

Login with Multiple OAuth Providers using Omniauth Discussion

General • Asked by Chris Oliver

Fallback

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.

Fallback

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!


Fallback

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?

Fallback

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.

Fallback

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.

Fallback

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

Fallback

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.

Fallback

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.


Fallback

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 twitter::Rest::Client.new 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 :)


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

Fallback

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

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


Login or create an account to join the conversation.