-
Notifications
You must be signed in to change notification settings - Fork 103
Returned nonce did not match. #22
Comments
I am also receiving this bug On the exact same line ... any update on this? |
Additional note: Very odd behavior I have just uncovered. I seem to be able to reproduce problem in Safari and Chrome but not in Firefox ... This is very confusing! |
Ok I found a workaround. The fact that browsers seemed to be the variance I guessed it was tied to cookies. I changed the code and added the following: use Rack::Session::Cookie, This seems to work just fine! |
@adammartin is 'your_secret_goes_here' the nonce (or nonce related)? |
@adammartin Setting Rails to use Rack::Session::Cookie in
|
I have the same issue here, anyone has a solution using rails's Edit : worked fine with |
I tested and found the If you are using Rails, this patch should solve the problem and doesn't require messing with middleware. Note the patch is based on the more popular fork of this repo. Although it seems long it actually replaces very little code. Gemfile:
Create file config/initializers/azure_ad_patch.rb:
|
Did some googling and tinkering a bit today, and I really like the solution that @pierre-pretorius suggested. It works without having to set SameSite to In order to work in development though, you will need to run I also don't know where to submit a patch. @microsoft / @AzureAD doesn't seem to care about this repo of theirs, and according to @davevanfleet's comment on #54, @planio-gmbh's fork is no longer super active, either. |
If you submit a PR on my repo I'm happy to merge it in. I don't mind maintaining the repo (but could probably use some help updating the original tests, since most of them are currently failing after updating the dependencies to allow this to work with the more up-to-date google omniauth gem - once the tests and CI/CD are back up and running smoothly maintaining the repo will be fine). |
…ivedirectory#22, in the interest of eliminating "Returned nonce did not match" errors
This happens with Rails 6.1+ because it uses a SameSite policy for cookies by default. This can be bypassed for AD authentication by adding the following to your config.action_dispatch.cookies_same_site_protection = lambda { |request|
# No SameSite attribute for azureactivedirectory since it uses
# session cookie to send a nonce and verify it on the callback.
return if request.fullpath.include?("azureactivedirectory")
:lax
} This works without having to use any other workarounds or patching the strategy to use cache. |
@pulkit110 I feel like you just saved half a day of my life with this - thank you. |
When I try to login using activedirectory I get the follow error and stacktrace:
It fails here https://github.com/AzureAD/omniauth-azure-activedirectory/blob/master/lib/omniauth/strategies/azure_activedirectory.rb#L289
I'm trying to use ominauth-azure_activedirectory in combination with Devise, my config looks like this:
Is my setup wrong? Or is it a bug in this library?
The text was updated successfully, but these errors were encountered: