Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Omniauth.allowed_methods' as routing verbs for the auth path: #5508

Merged

Conversation

Edouard-chin
Copy link
Contributor

@Edouard-chin Edouard-chin commented Jul 7, 2022

Use Omniauth.allowed_methods' as routing verbs for the auth path:

  • Context

    Since version 2.0.0, Omniauth no longer recognizes GET request
    on the auth path (/users/auth/<provider>). POST is the only
    verb that is by default recognized in order to mitigate CSRF
    attack. https://github.com/omniauth/omniauth/blob/66110da85e3106d9c9b138d384267a9397c75fe7/lib/omniauth/strategy.rb#L205

    Ultimatelly, when a user try to access GET /users/auth/facebook,
    Devise passthru action will be called which just return a raw 404 page.

    Problem

    There is no problem per se and everything work. However the
    advantage of not matching GET request at the router layer allows
    to get that same 404 page stylized for "free" (Rails ending up
    rendering the 404 page of the app).

    I believe it's also more consistent and less surprising for users
    if this passthru action don't get called.

    Drawback

    An application can no longer override the passthru to perform
    the logic it wants (i.e. redirect the user). (Though, worth to mention that the passthru action was originally not meant to be used as fallback main_app.user_omniauth_authorize_path throws error #1843 (comment) , but maybe this has become a hidden feature over the years :D)

    If this is a dealbreaker, feel free to close this PR :).

- ### Context

  Since version 2.0.0, Omniauth no longer recognizes `GET` request
  on the auth path (`/users/auth/<provider>`). `POST` is the only
  verb that is by default recognized in order to mitigate CSRF
  attack. https://github.com/omniauth/omniauth/blob/66110da85e3106d9c9b138d384267a9397c75fe7/lib/omniauth/strategy.rb#L205

  Ultimatelly, when a user try to access `GET /users/auth/facebook`,
  Devise [passthru action](https://github.com/heartcombo/devise/blob/6d32d2447cc0f3739d9732246b5a5bde98d9e032/app/controllers/devise/omniauth_callbacks_controller.rb#L6)
  will be called which just return a raw 404 page.

  ### Problem

  There is no problem per se and everything work. However the
  advantage of not matching GET request at the router layer allows
  to get that same 404 page stylized for "free" (Rails ending up
  rendering the 404 page of the app).

  I believe it's also more consistent and less surprising for users
  if this passthru action don't get called.

  ### Drawback

  An application can no longer override the `passthru` to perform
  the logic it wants (i.e. redirect the user).

  If this is a dealbreaker, feel free to close this PR :).
@rafaelfranca rafaelfranca force-pushed the ec-omniauth-allowed-methods branch from f524ef3 to 4f82235 Compare June 9, 2023 23:46
@rafaelfranca rafaelfranca merged commit 1b0ef1d into heartcombo:main Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants