From 9c518ea4432dbd398bcbf7e6cde94273166f95e7 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Fri, 26 Jun 2026 14:49:13 -0700 Subject: [PATCH] chore: simplify signals token auth --- .../api/v1/internal/accounts_controller.rb | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/enterprise/app/controllers/platform/api/v1/internal/accounts_controller.rb b/enterprise/app/controllers/platform/api/v1/internal/accounts_controller.rb index ce0da489b..ece1a7756 100644 --- a/enterprise/app/controllers/platform/api/v1/internal/accounts_controller.rb +++ b/enterprise/app/controllers/platform/api/v1/internal/accounts_controller.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class Platform::Api::V1::Internal::AccountsController < ActionController::API - CONFIG_KEY = 'CHATWOOT_CLOUD_SIGNALS_API_TOKEN' DEFAULT_LIMIT = 100 MAX_LIMIT = 1000 @@ -19,29 +18,13 @@ class Platform::Api::V1::Internal::AccountsController < ActionController::API end def authenticate_internal_token! - return if valid_token? + token = request.headers[:api_access_token] || request.headers[:HTTP_API_ACCESS_TOKEN] + config_token = GlobalConfigService.load('CHATWOOT_CLOUD_SIGNALS_API_TOKEN', nil) + return if token.present? && config_token.present? && ActiveSupport::SecurityUtils.secure_compare(token, config_token) render json: { error: 'Invalid access_token' }, status: :unauthorized end - def valid_token? - internal_token.present? && - request_token.present? && - ActiveSupport::SecurityUtils.secure_compare(request_token, internal_token) - end - - def request_token - bearer_token || request.headers[:api_access_token] || request.headers[:HTTP_API_ACCESS_TOKEN] - end - - def bearer_token - request.authorization&.split&.then { |scheme, token| token if scheme&.casecmp('Bearer')&.zero? } - end - - def internal_token - @internal_token ||= GlobalConfigService.load(CONFIG_KEY, nil) - end - def filtered_accounts scope = Account.order(:created_at, :id) scope = scope.where('created_at >= ?', Time.zone.at(params[:since].to_i)) if params[:since].present?