Ask A Question

Notifications

You’re not receiving notifications from this thread.

Login with Multiple OAuth Providers using Omniauth Discussion

Alex Musayev 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 alice@example.com, 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.

Reply

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!

Reply

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?

Reply
Dan Frenette 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.

Reply

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

Reply

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.

Reply

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.

Reply

I am stuck with this issue. Newbie like me + outdated materials = no idea what I am doing :)
I tried to https://github.com/heartcombo/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address but that didn't let me to login via GitHub. Should I try to solve this issue from devise side or omniauth? Thanks

Reply

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 :)

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

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

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

Reply

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

Reply

Hi Chris - I noticed the t.text :auth column in the migration. Was that intended to store the whole hash that comes over in case you wanted to pick it over for more data? It doesn't appear to be in use.

Reply

Exactly, there might be some additional things we need that are unique to one service, so having the full auth hash is useful.

Reply

:+1:. I also noticed that the forum email notification misattributed my comment to "BrianGVose". Looks like there's a bug there.

Reply
Join the discussion
Create an account Log in

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

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

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