Skip to content

Commit

Permalink
FIX: Add Rails 7+ compatibility
Browse files Browse the repository at this point in the history
When redirecting to an external URL with Rails 7+, the
`allow_other_host` option is needed.
  • Loading branch information
Flink committed Jun 27, 2024
1 parent d9ac173 commit 6d0900f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/controllers/salesforce/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class AdminController < ::Admin::AdminController
skip_before_action :check_xhr, :preload_json

def authorize
redirect_to "#{SiteSetting.salesforce_authorization_server_url}/services/oauth2/authorize?client_id=#{SiteSetting.salesforce_client_id}&redirect_uri=#{Discourse.base_url}&response_type=code"
redirect_to "#{SiteSetting.salesforce_authorization_server_url}/services/oauth2/authorize?client_id=#{SiteSetting.salesforce_client_id}&redirect_uri=#{Discourse.base_url}&response_type=code",
allow_other_host: true
end
end
end
21 changes: 21 additions & 0 deletions spec/requests/admin_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require "rails_helper"
require_relative "../spec_helper"

RSpec.describe ::Salesforce::AdminController do
include_context "with salesforce spec helper"

fab!(:admin)

describe "#authorize" do
before { sign_in(admin) }

it "redirects to the Salesforce authorization server" do
get "/salesforce/admin/authorize"
expect(response).to redirect_to(
"https://login.salesforce.com/services/oauth2/authorize?client_id=SALESFORCE_CLIENT_ID&redirect_uri=#{Discourse.base_url}&response_type=code",
)
end
end
end

0 comments on commit 6d0900f

Please sign in to comment.