I am using Railscast Episode # 250 to implement authentication from scratch. However, now I want to implement Facebook login. From googling I’ve found that OmniAuth and Devise are the prime contenders to do this in Rails
However, this example page is confusing me: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
It states:
With Rails 3.0.3, use this in your Gemfile instead if rails is having
trouble loading oauth core:gem “omniauth”
Next, you need to declare the provider in your
config/initializers/devise.rb:config.omniauth :facebook, “APP_ID”, “APP_SECRET”
Question
Are omniauth and devise interelated?
What should I do to implement Facebook login in my authentication based on Railscast 250
In your specific case you can think that Devise allows your application to authenticate users using a form (ex: by using an email and password) or an authentication token, Omniauth allows your application to “speak” to the Facebook servers to authenticate a user. In other words Omniauth sits on top of Devise and extends the number of ways your user can authenticate.
To implement Facebook login you need to:
0) configure devise: just follow this: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
1) expose a link in your view that when clicked by the user will tell Omniauth to start “speaking” to the Facebook server.
2) At one point the Facebook server will call you app so you have to implement a controller to respond to Facebook
Now you will notice that I call a User.create_user(registration_hash). This method implementation will depend on how your app create a user but at the minimum the method has to create a user and assign to it a random password:
Note: My app support login with other service so I have implemented a table that contain authentication tokens.
Hope this can get you started.