From 59aede5b006d5a11ebe3ec1beab634b05f2a6905 Mon Sep 17 00:00:00 2001 From: David Gil Date: Tue, 25 Aug 2015 14:15:24 +0200 Subject: [PATCH] adds Google OAuth2 support --- Gemfile | 2 +- Gemfile.lock | 4 ++++ app/controllers/users/omniauth_callbacks_controller.rb | 3 +-- app/views/devise/_omniauth_form.html.erb | 1 + config/deploy/shared/secrets.yml.erb | 2 ++ config/initializers/devise.rb | 1 + config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ config/secrets.yml.example | 6 ++++++ 9 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 6365cc67f..e997090f4 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ gem 'devise' gem 'omniauth' gem 'omniauth-twitter' gem 'omniauth-facebook' -# gem 'omniauth-google-oauth2' +gem 'omniauth-google-oauth2' gem 'kaminari' gem 'acts_as_commentable_with_threading' diff --git a/Gemfile.lock b/Gemfile.lock index 0023fb231..b3f89ec62 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -213,6 +213,9 @@ GEM rack (~> 1.0) omniauth-facebook (2.0.1) omniauth-oauth2 (~> 1.2) + omniauth-google-oauth2 (0.2.6) + omniauth (> 1.0) + omniauth-oauth2 (~> 1.1) omniauth-oauth (1.1.0) oauth omniauth (~> 1.0) @@ -391,6 +394,7 @@ DEPENDENCIES letter_opener_web (~> 1.3.0) omniauth omniauth-facebook + omniauth-google-oauth2 omniauth-twitter paranoia pg diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index a0a90c400..8588ba243 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -15,8 +15,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController } end - # [:twitter, :facebook, :google_oauth2].each do |provider| - [:twitter, :facebook].each do |provider| + [:twitter, :facebook, :google_oauth2].each do |provider| provides_callback_for provider end diff --git a/app/views/devise/_omniauth_form.html.erb b/app/views/devise/_omniauth_form.html.erb index cf06d359f..fdd812b4f 100644 --- a/app/views/devise/_omniauth_form.html.erb +++ b/app/views/devise/_omniauth_form.html.erb @@ -2,5 +2,6 @@ <%= link_to t("omniauth.twitter.sign_in"), user_omniauth_authorize_path(:twitter), class: 'button radius expand' %> <%= link_to t("omniauth.facebook.sign_in"), user_omniauth_authorize_path(:facebook), class: 'button radius expand' %> +<%= link_to t("omniauth.google_oauth2.sign_in"), user_omniauth_authorize_path(:google_oauth2), class: 'button radius expand' %>
diff --git a/config/deploy/shared/secrets.yml.erb b/config/deploy/shared/secrets.yml.erb index b4fa2634f..42a8c48a6 100644 --- a/config/deploy/shared/secrets.yml.erb +++ b/config/deploy/shared/secrets.yml.erb @@ -6,4 +6,6 @@ twitter_secret: <%= ENV["TWITTER_SECRET"] %> facebook_key: <%= ENV["FACEBOOK_KEY"] %> facebook_secret: <%= ENV["FACEBOOK_SECRET"] %> + google_oauth2_key: <%= ENV["GOOGLE_KEY"] %> + google_oauth2_secret: <%= ENV["GOOGLE_SECRET"] %> server_name: <%= fetch(:server_name) %> diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index eb7ec1970..40f3e50b3 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -241,6 +241,7 @@ Devise.setup do |config| # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' config.omniauth :twitter, Rails.application.secrets.twitter_key, Rails.application.secrets.twitter_secret config.omniauth :facebook, Rails.application.secrets.facebook_key, Rails.application.secrets.facebook_secret + config.omniauth :google_oauth2, Rails.application.secrets.google_oauth2_key, Rails.application.secrets.google_oauth2_secret # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/locales/en.yml b/config/locales/en.yml index 15275eb82..279b2a00e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -155,3 +155,5 @@ en: sign_in: Sign in with Twitter facebook: sign_in: Sign in with Facebook + google_oauth2: + sign_in: Sign in with Google diff --git a/config/locales/es.yml b/config/locales/es.yml index 74fd1d2d1..98c463b1e 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -155,3 +155,5 @@ es: sign_in: Entra con Twitter facebook: sign_in: Entra con Facebook + google_oauth2: + sign_in: Entra con Google diff --git a/config/secrets.yml.example b/config/secrets.yml.example index fc872bdaa..1d1312ea6 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -18,6 +18,8 @@ development: twitter_secret: BBBB facebook_key: AAAA facebook_secret: BBBB + google_oauth2_key: AAAA + google_oauth2_secret: BBBB <<: *default test: @@ -26,6 +28,8 @@ test: twitter_secret: BBBB facebook_key: AAAA facebook_secret: BBBB + google_oauth2_key: AAAA + google_oauth2_secret: BBBB <<: *default production: @@ -34,4 +38,6 @@ production: twitter_secret: <%= ENV["TWITTER_SECRET"] %> facebook_key: <%= ENV["FACEBOOK_KEY"] %> facebook_secret: <%= ENV["FACEBOOK_SECRET"] %> + google_oauth2_key: <%= ENV["GOOGLE_KEY"] %> + google_oauth2_secret: <%= ENV["GOOGLE_SECRET"] %> <<: *default