Member-only story
Setup Google OAuth Without Devise
Implement Google login on your Ruby on Rails app with pure omniauth.
In another article, I explained how to implement Google OAuth by using Devise. Devise has its advantages if you're planning to implement more complex login flows or options, such as login via email, recovering passwords, expiring sessions, etc.
However, if you want to stick with the bare minimum, I'd purely rely on the Omniauth gem, which is what I describe in this article. Let's go!
Add dependencies to your Gemfile
We'll use the Omniauth gem, as well as its Google adapter.
gem 'omniauth'
gem 'omniauth-google-oauth2'
You can try with only the above, but the last time I tried it, I also needed to add a third gem, which provides a mitigation against a CSRF issue.
gem 'omniauth-rails_csrf_protection', '~> 0.1'
Now, run bundle install
to install these dependencies
Create the :users table
The absolute minimum is email, provider, and uid, but I usually go with a few extra columns such as image, first name, and last name.
The image field will be pre-filled from their Google image.