User login via google account is probably not something that you're not aware of. The simplest way to implement the same in your rails app is by using a gem called OmniAuth and its strategy, oauth2.
Setting them up in your project is extremely easy, just add these two gems in your Gemfile and run bundle update
gem 'omniauth'
gem "omniauth-google-oauth2"
Get your API key at: https://code.google.com/apis/console/. Note the Client ID and the Client Secret. You must also enable the "Contacts API" and "Google+ API" in the Google API console.
Create a file name omniauth.rb in config/initializers/ and add these lines to it.
Rails.application.config.middleware.use
OmniAuth::Builder do
provider :google_oauth2, 'CLIENT_ID', 'CLIENT_SECRET'
end
Replace CLIENT_ID with your Client ID, and CLIENT_SECRET with your Client Secret.
Now you have finished setting up omniauth for your rails application. Make sure to check the next part of this article where I tell you how to implement the login and logout functionality. Happy coding!
No comments:
Post a Comment