ruby on rails - Setting up facebook authentication schema with existing user schema -
i want integrate facebook app through oauth have existing user schema set up. here's current schema:
# table name: users # # id :integer not null, primary key # first_name :string(255) # last_name :string(255) # email :string(255) # created_at :datetime not null # updated_at :datetime not null # password_digest :string(255) # remember_token :string(255) # admin :boolean default(false) #
what best way add facebook auth using rails?
there still couple of different ways this.
use email people login facebook establish connection between facebook account , site account.
add new column users database (called uid, type string). when use oauth, hash of information user returned, including unique identifier. here's example. can store uid later use way login.
regardless of these implementation choices, you'll want use omniauth gem , omniauth-facebook gem (you need different gem every provider). see project's wiki more info. it's easy use. in case, working, have add these 2 gems gemfile:
gem 'omniauth' gem 'omniauth-facebook'
then create file setup strategies. convention naming omniauth.rb:
# config/initializers/omniauth.rb rails.application.config.middleware.use omniauth::builder provider :facebook, facebook_key, facebook_secret end
to api key , api secret need create facebook app handle oauth connection. head on https://developers.facebook.com/apps , create it. don't forget edit these setting:
settings>basic>website>site url: http://localhost:3000/ development/testing your_website_callback_url production
Comments
Post a Comment