Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenIdConnectProtocolValidationContext.Nonce was null

HI can someone please help imgetting below error when calling outlook rest api

IDX21323: RequireNonce is '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'. OpenIdConnectProtocolValidationContext.Nonce was null, OpenIdConnectProtocol.ValidatedIdToken.Payload.Nonce was not null. The nonce cannot be validated. If you don't need to check the nonce, set OpenIdConnectProtocolValidator.RequireNonce to 'false'. Note if a 'nonce' is found it will be evaluated.

like image 776
Vialli Fritz Avatar asked May 25 '18 20:05

Vialli Fritz


People also ask

How to validate the openidconnect nonce?

The nonce cannot be validated. If you don't need to check the nonce, set OpenIdConnectProtocolValidator.RequireNonce to 'false'. Note if a 'nonce' is found it will be evaluated. Source: Microsoft.IdentityModel.Protocols.OpenIdConnect

Why can’t I validate the AAD nonce?

A nonce cannot be validated. If you don’t need to check the nonce, set OpenIdConnectProtocolValidator.RequireNonce to ‘false’. Possible root cause is that the nonce cookie is missing or altered during the authentication with AAD. Please note that it is normal for application to throw this error if user

What if I don’t need to check the OIDC nonce?

If you don’t need to check the nonce, set OpenIdConnectProtocolValidator.RequireNonce to ‘false’.” Asp.net OpenID Connect (OIDC) middleware uses the nonce cookie to prevent security replay attack.

Is it possible to validate a nonce?

A nonce cannot be validated. If you don't need to check the nonce, set OpenIdConnectProtocolValidator.RequireNonce to 'false'. Server Error in '/ContractDocumentSubmission' Application. IDX10311: RequireNonce is 'true' (default) but validationContext.Nonce is null. A nonce cannot be validated.


3 Answers

aka IDX21323 points towards losing the nonce cookie (set by the initial Challenge call). Inspect your initial SignIn call (or WebForms postback SignIn) and confirm that you have a OpenIdConnect.nonce cookie actually set (Chrome network tab).

If not, I suspect that you have the same issue we had, which is that the OWIN Middleware sets the cookie, but its content gets accidentally overwritten by some other cookie modifications of your legacy application. This is very likely a bug of the OWIN middleware (see ASP.NET_SessionId + OWIN Cookies do not send to browser), as it handles cookies through its own OwinContext and Cookie representation implementation, which is not in sync with the standard HttpContext.

How to fix when you have the initial nonce cookie missing: We avoided any cookie changes during the SignIn request -> therefore the OWIN middleware can read/write its cookies with no interference.

like image 156
r3mark Avatar answered Oct 13 '22 12:10

r3mark


When setting the nonce cookie running on localhost (non-secure) in a Chromium based browser, it's blocked because of SameSite=none and it not being secure. The fix for this case is to change localhost to use SSL (use https on asp.net application running on localhost) and update the Azure AD redirect URL to match.

like image 33
Kevin Sears Avatar answered Oct 13 '22 11:10

Kevin Sears


In a WebForms app I got the same error when I used my machine name in the project url, but used "localhost" as my login redirect url. When I set them both to localhost the problem went away.

like image 3
Rich Avatar answered Oct 13 '22 11:10

Rich