Skip to content

Developer provider not working under Rails 7.0.2.3 #1061

Closed

Description

@barttenbrinke

Please complete all sections.

Configuration

  • Provider Gem: omniauth-2.0.4
  • Ruby Version: 2.7.5
  • Framework: rails 7.0.2.3
  • Platform: ubuntu

Expected Behavior

Gemfile

gem 'omniauth'
gem "omniauth-rails_csrf_protection"

config/initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :developer
end

app/views/sessions/new.html.erb

<%= form_tag('/auth/developer', method: 'post') do %>
  <button type='submit'>Login with Developer</button>
<% end %>

Clicking on Login should render the developer form and log you in using fake credentials.

Actual Behavior

The only thing in the log is:

Started POST "/auth/developer" for 127.0.0.1 at 2022-03-21 21:58:57 +0100
D, [2022-03-21T21:58:57.950088 #3941647] DEBUG -- : (developer) Request phase initiated.

So the middleware is hit, but there is nothing after this.

Steps to Reproduce

gem install rails --version 7.0.2.3
rails new --css bootstrap
Add the code in expected behaviour.
bundle install
rails s
click Login

Activity

  1. changed the title [-]Developer mode not working under Rails 7.0.2.3[/-] [+]Developer provider not working under Rails 7.0.2.3[/+] on Mar 21, 2022
  2. barttenbrinke commented on Mar 21, 2022

    @barttenbrinke
    ContributorAuthor

    I also am unable to get omniauth-keycloak to work in Rails 7, so that is probably related to omniauth having some issues with rails 7. My gut feeling is that there is something wrong in the middleware handling, but I cannot put my finger on the root cause atm.

  3. barttenbrinke commented on Mar 21, 2022

    @barttenbrinke
    ContributorAuthor

    I think this might be the new turbo links being strange. Changed the view to:

    <%= form_tag('/auth/developer', method: 'post', data: {turbo: false}) do %>
      <button type='submit'>Login with Developer</button>
    <% end %>
    

    Then that seems to work.

  4. BobbyMcWho commented on Mar 21, 2022

    @BobbyMcWho
    Member

    @barttenbrinke glad you got it working, would you mind making a PR to the readme calling out this, and/or add to the wiki?

  5. barttenbrinke commented on Mar 21, 2022

    @barttenbrinke
    ContributorAuthor

    @BobbyMcWho The Readme is sort of lacking some valuable info :) I will look into it tomorrow.

  6. barttenbrinke commented on Mar 22, 2022

    @barttenbrinke
    ContributorAuthor

    @BobbyMcWho The PR is here ^^.

  7. masterkain commented on Sep 4, 2022

    @masterkain

    I have an issue with the code proposed in the readme in a vanilla rails 7 app
    https://github.com/omniauth/omniauth#rails-without-devise

    I hit http://0.0.0.0:3000/auth/developer and this is the form:

    <%= form_tag('/auth/developer', method: 'post', data: { turbo: false }) do %>
      <button type='submit'>Login with Developer</button>
    <% end %>
    

    I submit but:

    DEBUG -- omniauth: (developer) Callback phase initiated.
    ActionController::RoutingError (No route matches [POST] "/auth/developer/callback"):
    

    for some reason omniauth callback calls the callback in POST, in the routes we have defined a get.
    even if I switch to POST I get rails authenticity token issues.

  8. masterkain commented on Sep 4, 2022

    @masterkain

    I proposed some further changes in the linked PR above, also putting back a skip_before_action that was there before the rewrite

  9. yshmarov commented on Jan 9, 2023

    @yshmarov

    I'd just like to add that you don't have to use a form_tag, you can just use a button_to:

    <%= button_to "Sign in with Github", "/auth/github", data: { turbo: false } %>
    
  10. barttenbrinke commented on Jan 9, 2023

    @barttenbrinke
    ContributorAuthor

    I proposed some further changes in the linked PR above, also putting back a skip_before_action that was there before the rewrite

    The skip_before_action should no longer be needed with the gem "omniauth-rails_csrf_protection" gem. The POST should be handled by the omni-auth middelware, which does the signon (possibly through a 3rd party) and then redirects the user to the /callback route. That should therefore be GET.

    Have you got the developer middleware set up correctly?

    I used the form_tag in the example, to show developers exactly what they what the code is meant to do. button_to obfuscates it a bit IMHO.

  11. dutow commented on Jan 29, 2023

    @dutow

    I'm also getting the same errors with the developer provider.

    Looking at the source: https://github.com/omniauth/omniauth/blob/master/lib/omniauth/strategies/developer.rb#L38

    The developer provider clearly creates a form that sends a POST request to the callback URL, without a CSRF token. How should this work without also allowing POST requests and disabling CSRF protection for create?

    Edit: after looking more into the source, it seems like that the rails_csrf_protection gem and the CVE is about the initial step (using POST /auth/developer instead of GET /auth/developer), it has nothing to do with the callback part.

  12. barttenbrinke commented on Jan 31, 2023

    @barttenbrinke
    ContributorAuthor

    gem "omniauth-rails_csrf_protection" should take care of that.

  13. cycomachead commented on Mar 3, 2023

    @cycomachead
    Contributor

    Following the steps in the README, I am also running into this issue with the :developer provider.

    The csrf_proctection gem only handles validation of tokens, but the developer form does not have an authenticity token anywhere...

    My current solution is to do what other's have suggested, which is to skip verification on the /callback route, but only in development.

    The OmniAuth developer form should probably include some authenticity token, though I'll be honest, I'm not immediately sure how to best do this... I'm not versed enough in the Rails internals to be able to generate an authenticity_token from within the omniauth middleware setup.

    I was exploring playing with a monkey patch, and it's not hard to find a spot to inject a new hidden field into the form. (This could be an option passed to the provider function. But I didn't have the time to figure out how to actually generate a token rails would accept.

    EDIT:

    Actually, I don't see why we need to worry about CSRF here, if many the strategies use GET, we should just have the :developer strategy form make a GET request, which seems simpler. #1106

  14. added a commit that references this issue on Mar 3, 2023
    480a2ff
  15. spryffee commented on Mar 8, 2023

    @spryffee

    Having the same issue. That would be great if it gets patched soon. @cycomachead thanks for the PR

  16. abartov commented on Apr 5, 2023

    @abartov

    Thank you @cycomachead for the patch!

  17. dave315 commented on May 7, 2023

    @dave315

    Silly question, is there a way to use this patch before it is merged? It's approved but not merged yet. What's the best way to do that?

  18. added theissue type on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions