You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Developer provider not working under Rails 7.0.2.3 #1061
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
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.
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 %>
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.
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.
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.
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
Activity
[-]Developer mode not working under Rails 7.0.2.3[/-][+]Developer provider not working under Rails 7.0.2.3[/+]barttenbrinke commentedon Mar 21, 2022
I also am unable to get
omniauth-keycloakto 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.barttenbrinke commentedon Mar 21, 2022
I think this might be the new turbo links being strange. Changed the view to:
Then that seems to work.
BobbyMcWho commentedon Mar 21, 2022
@barttenbrinke glad you got it working, would you mind making a PR to the readme calling out this, and/or add to the wiki?
barttenbrinke commentedon Mar 21, 2022
@BobbyMcWho The Readme is sort of lacking some valuable info :) I will look into it tomorrow.
barttenbrinke commentedon Mar 22, 2022
@BobbyMcWho The PR is here ^^.
masterkain commentedon Sep 4, 2022
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/developerand this is the form:I submit but:
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.
masterkain commentedon Sep 4, 2022
I proposed some further changes in the linked PR above, also putting back a
skip_before_actionthat was there before the rewriteyshmarov commentedon Jan 9, 2023
I'd just like to add that you don't have to use a
form_tag, you can just use abutton_to:barttenbrinke commentedon Jan 9, 2023
The
skip_before_actionshould 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.
dutow commentedon Jan 29, 2023
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.
barttenbrinke commentedon Jan 31, 2023
gem "omniauth-rails_csrf_protection"should take care of that.cycomachead commentedon Mar 3, 2023
Following the steps in the README, I am also running into this issue with the
:developerprovider.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
/callbackroute, 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 anauthenticity_tokenfrom 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 theproviderfunction. 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
:developerstrategy form make a GET request, which seems simpler. #1106Use GET with :developer strategy.
spryffee commentedon Mar 8, 2023
Having the same issue. That would be great if it gets patched soon. @cycomachead thanks for the PR
abartov commentedon Apr 5, 2023
Thank you @cycomachead for the patch!
dave315 commentedon May 7, 2023
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?