Google Authentication Strategy for Rails 5 Application

RKH
The Startup
Published in
2 min readJun 14, 2019

--

When creating my rails final project, WINELOG, I found it difficult to implement social login with Google. I also found there was a lack of recent documentation or blog posts on the subject.

Here’s a quick guide on how to set up Google log in.

Create app in Google Developers Console. Select credentials, then ‘create credentials’, and select ‘Create OAuth client ID’, then select ‘web application’.

Here you’ll be able to see the client ID and client secret — you’ll need those soon!

Add in the authorized redirect URIs — http://localhost:3000/auth/google_oauth2/callback works for testing in the rails server, but remember to add the URI for the production well.

Add necessary gems to your gem file. You’ll need to add three gems — gem 'omniauth', gem 'dotenv-rails' and gem 'omniauth-google-oauth2'. Run bundle in the terminal.

Create a .env file in the root directory of your app. Add the following code to the file — and remember to add this file to your gitignore.

GOOGLE_CLIENT_ID=Your client id
GOOGLE_CLIENT_SECRET=Your client secret

--

--