Skip to content

Commit

Permalink
Merge pull request #5508 from Edouard-chin/ec-omniauth-allowed-methods
Browse files Browse the repository at this point in the history
Use Omniauth.allowed_methods' as routing verbs for the auth path:
  • Loading branch information
rafaelfranca committed Jun 9, 2023
2 parents 8bb41ad + 4f82235 commit 1b0ef1d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/devise/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def devise_omniauth_callback(mapping, controllers) #:nodoc:
match "#{path_prefix}/#{provider}",
to: "#{controllers[:omniauth_callbacks]}#passthru",
as: "#{provider}_omniauth_authorize",
via: [:get, :post]
via: OmniAuth.config.allowed_request_methods

match "#{path_prefix}/#{provider}/callback",
to: "#{controllers[:omniauth_callbacks]}##{provider}",
Expand Down
22 changes: 22 additions & 0 deletions test/integration/omniauthable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,28 @@ def stub_action!(name)
end
end

test "authorization path via GET when Omniauth allowed_request_methods includes GET" do
original_allowed = OmniAuth.config.allowed_request_methods
OmniAuth.config.allowed_request_methods = [:get, :post]

get "/users/auth/facebook"

assert_response(:redirect)
ensure
OmniAuth.config.allowed_request_methods = original_allowed
end

test "authorization path via GET when Omniauth allowed_request_methods doesn't include GET" do
original_allowed = OmniAuth.config.allowed_request_methods
OmniAuth.config.allowed_request_methods = [:post]

assert_raises(ActionController::RoutingError) do
get "/users/auth/facebook"
end
ensure
OmniAuth.config.allowed_request_methods = original_allowed
end

test "generates a link to authenticate with provider" do
visit "/users/sign_in"
assert_select "form[action=?][method=post]", "/users/auth/facebook" do
Expand Down

0 comments on commit 1b0ef1d

Please sign in to comment.