Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions notes
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def self.find_for_google_oauth2(access_token, signed_in_resource=nil)
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






class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
user = User.from_omniauth(request.env['omniauth.auth'],current_user)
if user.persisted?
render json: user
else
render "There was an error while trying to authenticate you..."

end




GOOGLE_CLIENT_ID=322311415937-oo9j3m1h0v9q7vr3f7qi49ikldumprru.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=UtL2iN-hTs-kJnU9kckhslMQ

config.omniauth :google_oauth2, ENV['GOOGLE_OAUTH_CLIENT_ID'], ENV['GOOGLE_OAUTH_CLIENT_SECRET'],
scope: 'profile'



config.session_store :cookie_store, key: '_interslice_session'
config.middleware.use ActionDispatch::Cookies # Required for all session management
config.middleware.use ActionDispatch::Session::CookieStore, config.session_options