feat: add google concern

This commit is contained in:
Shivam Mishra
2024-06-02 19:35:41 +05:30
parent 4582794ad4
commit d974be86ee
2 changed files with 24 additions and 8 deletions
+20
View File
@@ -0,0 +1,20 @@
module GoogleConcern
extend ActiveSupport::Concern
def google_client
app_id = GlobalConfigService.load('GOOGLE_OAUTH_CLIENT_ID', nil)
app_secret = GlobalConfigService.load('GOOGLE_OAUTH_CLIENT_SECRET', nil)
::OAuth2::Client.new(app_id, app_secret, {
site: 'https://oauth2.googleapis.com',
authorize_url: 'https://accounts.google.com/o/oauth2/auth',
token_url: '/token'
})
end
private
def base_url
ENV.fetch('FRONTEND_URL', 'http://localhost:3000')
end
end
@@ -1,4 +1,6 @@
class Google::CallbacksController < OauthCallbackController
include GoogleConcern
private
def provider_name
@@ -10,13 +12,7 @@ class Google::CallbacksController < OauthCallbackController
end
def oauth_client
app_id = GlobalConfigService.load('GOOGLE_OAUTH_CLIENT_ID', nil)
app_secret = GlobalConfigService.load('GOOGLE_OAUTH_CLIENT_SECRET', nil)
::OAuth2::Client.new(app_id, app_secret, {
site: 'https://oauth2.googleapis.com',
authorize_url: 'https://accounts.google.com/o/oauth2/auth',
token_url: '/token'
})
# from GoogleConcern
google_client
end
end