From 5c1d01df22b28429c18c1137b398317c728dd315 Mon Sep 17 00:00:00 2001 From: Ayush Maurya Date: Tue, 2 Feb 2021 01:04:54 +0530 Subject: [PATCH] notes --- notes | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 notes diff --git a/notes b/notes new file mode 100644 index 0000000..00ad658 --- /dev/null +++ b/notes @@ -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