Skip to content

Commit 4979621

Browse files
app-rails: Update template-application-rails to version 1.0.0.post1.dev0+ba942ae
1 parent a135606 commit 4979621

7 files changed

Lines changed: 54 additions & 13 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: v0.4.1-39-g91f9597
2+
_commit: v1.0.0-1-gba942ae
33
_src_path: https://github.com/navapbc/template-application-rails
44
app_local_port: 3100
55
app_name: app-rails

app-rails/app/controllers/application_controller.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,40 @@ def after_sign_in_path_for(resource)
2828

2929
users_account_path
3030
end
31+
32+
# Intercept redirect_to to replace the host with APP_HOST (the public hostname).
33+
def redirect_to(options = {}, response_options_and_flash = {})
34+
app_host = ENV["APP_HOST"]
35+
if app_host.present?
36+
options = case options
37+
when String
38+
if options.start_with?("http://", "https://")
39+
options.sub(%r{\Ahttps?://[^/]+}, "https://#{app_host}")
40+
elsif options.start_with?("/")
41+
"https://#{app_host}#{options}"
42+
else
43+
options
44+
end
45+
when Hash
46+
{ host: app_host, protocol: "https" }.merge(options)
47+
else
48+
options
49+
end
50+
response_options_and_flash = response_options_and_flash.merge(allow_other_host: true)
51+
end
52+
super
53+
end
54+
55+
private
56+
57+
# Compare the Origin header against the configured APP_HOST (the public hostname) instead.
58+
def valid_request_origin?
59+
app_host = ENV["APP_HOST"]
60+
if app_host.present?
61+
request.origin.nil? || request.origin == "#{request.scheme}://#{app_host}"
62+
else
63+
super
64+
end
65+
end
66+
3167
end

app-rails/app/controllers/users/mfa_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def new
3434
# forcing the user to log in again
3535
if current_user.access_token_expires_within_minutes?(current_user.access_token, 5)
3636
sign_out(current_user)
37-
redirect_to new_user_session_path
37+
redirect_to new_user_session_url
3838
return
3939
end
4040

@@ -58,12 +58,12 @@ def create
5858
return redirect_to({ action: :new }, flash: { errors: [ e.message ] })
5959
end
6060

61-
redirect_to root_path, { notice: I18n.t("users.mfa.create.success") }
61+
redirect_to root_url, { notice: I18n.t("users.mfa.create.success") }
6262
end
6363

6464
def destroy
6565
auth_service.disable_software_token(current_user)
66-
redirect_to users_account_path, notice: I18n.t("users.accounts.edit.mfa_successfully_disabled")
66+
redirect_to users_account_url, notice: I18n.t("users.accounts.edit.mfa_successfully_disabled")
6767
end
6868

6969
private

app-rails/app/controllers/users/passwords_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def send_reset_password_instructions
2424
return render :forgot, status: :unprocessable_content
2525
end
2626

27-
redirect_to users_reset_password_path
27+
redirect_to users_reset_password_url
2828
end
2929

3030
def reset
@@ -50,7 +50,7 @@ def confirm_reset
5050
return render :reset, status: :unprocessable_content
5151
end
5252

53-
redirect_to new_user_session_path, notice: I18n.t("users.passwords.reset.success")
53+
redirect_to new_user_session_url, notice: I18n.t("users.passwords.reset.success")
5454
end
5555

5656
private

app-rails/app/controllers/users/registrations_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def create
2626
return render :new, status: :unprocessable_content
2727
end
2828

29-
redirect_to users_verify_account_path
29+
redirect_to users_verify_account_url
3030
end
3131

3232
def new_account_verification
@@ -50,7 +50,7 @@ def create_account_verification
5050
return render :new_account_verification, status: :unprocessable_content
5151
end
5252

53-
redirect_to new_user_session_path
53+
redirect_to new_user_session_url
5454
end
5555

5656
def resend_verification_code
@@ -65,7 +65,7 @@ def resend_verification_code
6565
auth_service.resend_verification_code(email)
6666

6767
flash[:notice] = I18n.t("users.registrations.new_account_verification.resend_success")
68-
redirect_to users_verify_account_path
68+
redirect_to users_verify_account_url
6969
end
7070

7171
private

app-rails/app/controllers/users/sessions_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def create
2222
@form.password
2323
)
2424
rescue Auth::Errors::UserNotConfirmed => e
25-
return redirect_to users_verify_account_path
25+
return redirect_to users_verify_account_url
2626
rescue Auth::Errors::BaseAuthError => e
2727
flash.now[:errors] = [ e.message ]
2828
return render :new, status: :unprocessable_content
@@ -31,7 +31,7 @@ def create
3131
unless response[:user].present?
3232
session[:challenge_session] = response[:session]
3333
session[:challenge_email] = @form.email
34-
return redirect_to session_challenge_path
34+
return redirect_to session_challenge_url
3535
end
3636

3737
auth_user(response[:user], response[:access_token])
@@ -40,7 +40,7 @@ def create
4040
# Show MFA
4141
def challenge
4242
if session[:challenge_session].nil?
43-
return redirect_to new_user_session_path
43+
return redirect_to new_user_session_url
4444
end
4545

4646
@form = Users::AuthAppCodeForm.new

app-rails/config/environments/production.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@
5050

5151
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
5252
# Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
53-
# config.assume_ssl = true
53+
config.assume_ssl = true
54+
55+
# Azure Application Gateway sets Host: <container-app-fqdn> on backend connections.
56+
# Set the default URL host to APP_HOST so that redirects use the public hostname
57+
# instead of the internal Container App FQDN.
58+
config.action_dispatch.default_url_options = { host: ENV["APP_HOST"] }
5459

5560
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
5661
config.force_ssl = true

0 commit comments

Comments
 (0)