Google authentication added

This commit is contained in:
Christoph Haas 2017-04-17 00:42:03 +02:00
parent f7258370a0
commit 2a7491edcd
7 changed files with 37 additions and 28 deletions

View file

@ -118,7 +118,7 @@ gem "sprockets"
# Authentication against Google, Facebook and others
gem 'omniauth'
# gem 'omniauth-amazon'
# gem 'omniauth-google-oauth2'
gem 'omniauth-google-oauth2'
# gem 'omniauth-github'
# gem 'omniauth-twitter'
gem 'omniauth-openid'

View file

@ -86,6 +86,8 @@ GEM
execjs (2.7.0)
fancybox2-rails (0.2.7)
railties (>= 3.1.0)
faraday (0.11.0)
multipart-post (>= 1.2, < 3)
ffi (1.9.18)
font-awesome-rails (4.7.0.1)
railties (>= 3.2, < 5.1)
@ -124,6 +126,7 @@ GEM
js_cookie_rails (2.1.4)
railties (>= 3.1)
json (1.8.6)
jwt (1.5.6)
libv8 (3.16.14.19)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
@ -149,6 +152,8 @@ GEM
minitest (>= 5.0)
ruby-progressbar
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nenv (0.3.0)
nio4r (2.0.0)
nokogiri (1.7.1)
@ -156,9 +161,23 @@ GEM
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
oauth2 (1.3.1)
faraday (>= 0.8, < 0.12)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
omniauth (1.6.1)
hashie (>= 3.4.6, < 3.6.0)
rack (>= 1.6.2, < 3)
omniauth-google-oauth2 (0.4.1)
jwt (~> 1.5.2)
multi_json (~> 1.3)
omniauth (>= 1.1.1)
omniauth-oauth2 (>= 1.3.1)
omniauth-oauth2 (1.4.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
@ -307,6 +326,7 @@ DEPENDENCIES
minitest-rails
minitest-reporters
omniauth
omniauth-google-oauth2
omniauth-openid
paperclip
pg

View file

@ -11,15 +11,11 @@ https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
## Google+
The client ID for the debshots application is:
The client ID for the debshots and the private key must be set as environment
variables before running the application:
398593918966-0fpmit0pb6ptio1ndsie5dfcnqhei63l.apps.googleusercontent.com
The private key is:
uRQq_dLs1kx7l5sYIyEyPVRc
(This information is connected to the christoph.haas@gmail.com account.)
* GOOGLE_CLIENT_ID=…
* GOOGLE_CLIENT_SECRET=…
## Amazon

View file

@ -11,6 +11,10 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
login_via 'StackExchange'
end
def google_oauth2
login_via 'Google'
end
def login_via(provider_name)
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])

View file

@ -10,7 +10,11 @@ class User < ApplicationRecord
# :validatable,
:timeoutable,
# :lockable,
:omniauthable, :omniauth_providers => [:launchpad,:stackexchange]
:omniauthable, :omniauth_providers => [
:launchpad,
:stackexchange,
:google_oauth2
]
def self.from_omniauth(auth)
@ -23,19 +27,5 @@ class User < ApplicationRecord
user.password = Devise.friendly_token[0,20]
end
end
#
# def self.from_omniauth(access_token)
# data = access_token.info
# user = User.where(:email => data["email"]).first
#
# # Uncomment the section below if you want users to be created if they don't exist
# # unless user
# # user = User.create(name: data["name"],
# # email: data["email"],
# # password: Devise.friendly_token[0,20]
# # )
# # end
# user
# end
end

View file

@ -39,6 +39,7 @@
= link_to "Sign in with Launchpad", user_launchpad_omniauth_authorize_path
= link_to "Sign in with StackExchange", user_stackexchange_omniauth_authorize_path
= link_to "Sign in with Google", user_google_oauth2_omniauth_authorize_path
/ div
/ = link_to image_tag('/images/sso/google.png'), user_google_oauth2_omniauth_authorize_path

View file

@ -274,10 +274,8 @@ Devise.setup do |config|
# config.omniauth_path_prefix = '/my_engine/users/auth'
# config.omniauth :launchpad, 'debshots'
# config.omniauth :google_oauth2, '398593918966-0fpmit0pb6ptio1ndsie5dfcnqhei63l.apps.googleusercontent.com', 'uRQq_dLs1kx7l5sYIyEyPVRc', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
#
# # config.omniauth :launchpad, 'Debian Screenshots', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
#
config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"], :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
# config.omniauth :amazon, 'amzn1.application-oa2-client.78d832919fc24456b0636762cf18efd9', '8c495d0940ca4100313c03e93b8b4240eef256d2fdbe672718506f29f5a20f61', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
config.omniauth :open_id, name: :stackexchange, identifier: 'https://openid.stackexchange.com', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}