Google authentication added
This commit is contained in:
parent
f7258370a0
commit
2a7491edcd
7 changed files with 37 additions and 28 deletions
|
|
@ -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"])
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue