refactor: common oauth_authorization_controller

This commit is contained in:
Shivam Mishra
2025-06-02 18:35:49 +05:30
parent 363169667d
commit 12957b7438
4 changed files with 20 additions and 36 deletions
@@ -1,6 +1,5 @@
class Api::V1::Accounts::Google::AuthorizationsController < Api::V1::Accounts::BaseController
class Api::V1::Accounts::Google::AuthorizationsController < Api::V1::Accounts::OauthAuthorizationController
include GoogleConcern
before_action :check_authorization
def create
redirect_url = google_client.auth_code.authorize_url(
@@ -21,16 +20,4 @@ class Api::V1::Accounts::Google::AuthorizationsController < Api::V1::Accounts::B
render json: { success: false }, status: :unprocessable_entity
end
end
def state
# return a signed id for the current account
# this is cryptographically verifyable
Current.account.to_sgid(expires_in: 15.minutes).to_s
end
private
def check_authorization
raise Pundit::NotAuthorizedError unless Current.account_user.administrator?
end
end
@@ -1,7 +1,6 @@
class Api::V1::Accounts::Instagram::AuthorizationsController < Api::V1::Accounts::BaseController
class Api::V1::Accounts::Instagram::AuthorizationsController < Api::V1::Accounts::OauthAuthorizationController
include InstagramConcern
include Instagram::IntegrationHelper
before_action :check_authorization
def create
# https://developers.facebook.com/docs/instagram-platform/instagram-api-with-instagram-login/business-login#step-1--get-authorization
@@ -21,10 +20,4 @@ class Api::V1::Accounts::Instagram::AuthorizationsController < Api::V1::Accounts
render json: { success: false }, status: :unprocessable_entity
end
end
private
def check_authorization
raise Pundit::NotAuthorizedError unless Current.account_user.administrator?
end
end
@@ -1,6 +1,5 @@
class Api::V1::Accounts::Microsoft::AuthorizationsController < Api::V1::Accounts::BaseController
class Api::V1::Accounts::Microsoft::AuthorizationsController < Api::V1::Accounts::OauthAuthorizationController
include MicrosoftConcern
before_action :check_authorization
def create
redirect_url = microsoft_client.auth_code.authorize_url(
@@ -17,16 +16,4 @@ class Api::V1::Accounts::Microsoft::AuthorizationsController < Api::V1::Accounts
render json: { success: false }, status: :unprocessable_entity
end
end
def state
# return a signed id for the current account
# this is cryptographically verifyable
Current.account.to_sgid(expires_in: 15.minutes).to_s
end
private
def check_authorization
raise Pundit::NotAuthorizedError unless Current.account_user.administrator?
end
end
@@ -0,0 +1,17 @@
class Api::V1::Accounts::OauthAuthorizationController < Api::V1::Accounts::BaseController
before_action :check_authorization
def state
Current.account.to_sgid(expires_in: 15.minutes).to_s
end
def base_url
ENV.fetch('FRONTEND_URL', 'http://localhost:3000')
end
private
def check_authorization
raise Pundit::NotAuthorizedError unless Current.account_user.administrator?
end
end