I created my authentication from scratch using Hartl’s Railstutorial http://ruby.railstutorial.org/chapters/modeling-users#sec:user_model.
I want to implement a Facebook and Twitter log in for my website project. I am comsidering using OmniAuth after watching Railscasts Simple Omniauth http://railscasts.com/episodes/241-simple-omniauth?view=comments.
In the video, we are instructed to generate a user model:
rails generate model user provider:string uid:string name:string
Is the uid unique to the Twitter and Facebook log in or is it the same thing as my id attribute in my User model?
Simply, do I need to add a uid column to my user model to implement OmniAuth?
Thanks!
The UID is the user id for facebook or twitter login. It is not the same as the ‘id’ field in the User model.
Omniauth uses an environment variable to set a hash. In this hash is a ‘uid’ key, which you will want to use to lookup your User in you database. It also sets a ‘provider’ key, so the combination of the ‘uid’ key and ‘provider’ key gives you the ability to look up your user record, e.g.
So, your model (User) will need to have both ‘provider’ and ‘uid’ columns for this to work.