Add default OAuths (#259)

This commit is contained in:
Riccardo Graziosi
2024-01-22 14:45:48 +01:00
committed by GitHub
parent 0828c9c879
commit 653e139a9e
32 changed files with 512 additions and 213 deletions

View File

@@ -3,6 +3,8 @@ class OAuth < ApplicationRecord
include ApplicationHelper
include Rails.application.routes.url_helpers
scope :include_defaults, -> { unscope(where: :tenant_id).where(tenant_id: Current.tenant).or(unscope(where: :tenant_id).where(tenant_id: nil, is_enabled: true)) }
attr_accessor :state
validates :name, presence: true, uniqueness: { scope: :tenant_id }
@@ -15,8 +17,20 @@ class OAuth < ApplicationRecord
validates :scope, presence: true
validates :json_user_email_path, presence: true
def is_default?
tenant_id == nil
end
def callback_url
add_subdomain_to(method(:o_auth_callback_url), id)
# Default OAuths are available to all tenants
# but must have a single callback url:
# for this reason, we don't preprend tenant subdomain
# but rather use the "login" subdomain
if self.is_default?
o_auth_callback_url(id, host: Rails.application.base_url, subdomain: "login")
else
add_subdomain_to(method(:o_auth_callback_url), id)
end
end
def authorize_url_with_query_params