Skip to content

Commit f811af0

Browse files
ihatov08ThiagoAnunciacao
authored andcommitted
add redirect_to options for rails7 allow_other_host (lynndylanhurley#1599)
1 parent 9ac9f04 commit f811af0

File tree

7 files changed

+17
-8
lines changed

7 files changed

+17
-8
lines changed

app/controllers/devise_token_auth/application_controller.rb

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ def success_message(name, email)
8484
end
8585
end
8686

87+
def redirect_options
88+
{}
89+
end
90+
8791
# When using a cookie to transport the auth token we can set it immediately in flows such as
8892
# reset password and OmniAuth success, rather than making the client scrape the token from
8993
# query params (to then send in the initial validate_token request).

app/controllers/devise_token_auth/confirmations_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def show
2424
redirect_to_link = DeviseTokenAuth::Url.generate(redirect_url, redirect_header_options)
2525
end
2626

27-
redirect_to(redirect_to_link)
27+
redirect_to(redirect_to_link, redirect_options)
2828
else
2929
if redirect_url
3030
redirect_to DeviseTokenAuth::Url.generate(redirect_url, account_confirmation_success: false), allow_other_host: true

app/controllers/devise_token_auth/omniauth_callbacks_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def redirect_callbacks
2323
session['dta.omniauth.auth'] = request.env['omniauth.auth'].except('extra')
2424
session['dta.omniauth.params'] = request.env['omniauth.params']
2525

26-
redirect_to redirect_route, status: 307
26+
redirect_to redirect_route, {status: 307}.merge(redirect_options)
2727
end
2828

2929
def get_redirect_route(devise_mapping)
@@ -228,7 +228,7 @@ def render_data_or_redirect(message, data, user_data = {})
228228
elsif auth_origin_url # default to same-window implementation, which forwards back to auth_origin_url
229229

230230
# build and redirect to destination url
231-
redirect_to DeviseTokenAuth::Url.generate(auth_origin_url, data.merge(blank: true)), allow_other_host: true
231+
redirect_to DeviseTokenAuth::Url.generate(auth_origin_url, data.merge(blank: true).merge(redirect_options)), allow_other_host: true
232232
else
233233

234234
# there SHOULD always be an auth_origin_url, but if someone does something silly

app/controllers/devise_token_auth/passwords_controller.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def edit
4949
yield @resource if block_given?
5050

5151
if require_client_password_reset_token?
52-
redirect_to DeviseTokenAuth::Url.generate(@redirect_url, reset_password_token: resource_params[:reset_password_token])
52+
redirect_to DeviseTokenAuth::Url.generate(@redirect_url, reset_password_token: resource_params[:reset_password_token]),
53+
redirect_options
5354
else
5455
if DeviseTokenAuth.cookie_enabled
5556
set_token_in_cookie(@resource, token)
@@ -60,7 +61,8 @@ def edit
6061
token.client,
6162
redirect_header_options)
6263
redirect_to(@resource.build_auth_url(@redirect_url,
63-
redirect_headers))
64+
redirect_headers),
65+
redirect_options)
6466
end
6567
else
6668
render_edit_error

app/controllers/devise_token_auth/unlocks_controller.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def show
4444
token.client,
4545
redirect_header_options)
4646
redirect_to(@resource.build_auth_url(after_unlock_path_for(@resource),
47-
redirect_headers))
47+
redirect_headers),
48+
redirect_options)
4849
else
4950
render_show_error
5051
end

test/dummy/app/controllers/overrides/confirmations_controller.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def show
1919
redirect_header_options)
2020

2121
redirect_to(@resource.build_auth_url(params[:redirect_url],
22-
redirect_headers))
22+
redirect_headers),
23+
redirect_options)
2324
else
2425
raise ActionController::RoutingError, 'Not Found'
2526
end

test/dummy/app/controllers/overrides/passwords_controller.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def edit
2626
token.client,
2727
redirect_header_options)
2828
redirect_to(@resource.build_auth_url(params[:redirect_url],
29-
redirect_headers))
29+
redirect_headers),
30+
redirect_options)
3031
else
3132
raise ActionController::RoutingError, 'Not Found'
3233
end

0 commit comments

Comments
 (0)