Skip to content

Commit 6a2fc87

Browse files
authored
Update nonce validation error documentation.
Edit review per CI 2958
1 parent b10133e commit 6a2fc87

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

support/entra/entra-id/app-integration/troubleshoot-validation-context-nonce-null-mvc.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
11
---
22
title: Resolving nonce validation errors in ASP.NET MVC with OpenID Connect
3-
description: This article provides solutions to the common nonce validation errors encountered in ASP.NET MVC apps using OpenID Connect middleware.
3+
description: This article provides solutions to the common nonce validation errors that are encountered in ASP.NET MVC apps by using OpenID Connect middleware.
44
ms.date: 01/02/2025
55
ms.author: bachoang
66
ms.service: entra-id
77
ms.custom: sap:Development Developing or Registering apps with Microsoft identity platform
88
---
99

10-
# ValidationContext.Nonce is null errors in ASP.NET MVC apps
10+
# "ValidationContext.Nonce is null" errors in ASP.NET MVC apps
1111

12-
This article provides solutions to the common nonce validation errors encountered in ASP.NET MVC apps using OpenID Connect (OIDC) middleware.
12+
This article provides solutions to the common nonce validation errors that you might encounter in ASP.NET MVC apps by using OpenID Connect (OIDC) middleware.
1313

1414
## Common error messages
1515

16-
Depending on the version of Open Web Interface for .NET (OWIN) being used, you may encounter one of the following error messages:
16+
Depending on the version of Open Web Interface for .NET (OWIN) that you use, you might receive one of the following error messages:
1717

1818
- 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 do not need to check the nonce, set OpenIdConnectProtocolValidator.RequireNonce to false.
1919

20-
- IDX10311: RequireNonce is 'true' (default) but validationContext.Nonce is null. A nonce cannot be validated. If you do not need to check the nonce, set OpenIdConnectProtocolValidator.RequireNonce to false.
20+
- IDX10311: RequireNonce is 'true' (default) but validationContext.Nonce is null. A nonce cannot be validated. If you do not need to check the nonce, set OpenIdConnectProtocolValidator.RequireNonce to errorsfalse.
2121

2222
## Understanding nonce cookies
2323

24-
The ASP.NET OIDC middleware uses a nonce cookie to prevent [replay attacks](/dotnet/framework/wcf/feature-details/replay-attacks). As mentioned in the error, the app throws the exception when it can't find the nonce cookie in the authenticated request. Cookies are domain-based, meaning that once they're set for a specific domain, all subsequent requests to that domain will include these cookies until they expire or are deleted.
24+
The ASP.NET OIDC middleware uses a nonce cookie to prevent [replay attacks](/dotnet/framework/wcf/feature-details/replay-attacks). The app throws the exception if it can't find the nonce cookie in the authenticated request. Cookies are domain-based. This means that if the cookies are set for a specific domain, all subsequent requests to that domain will include the cookies until they expire or are deleted.
2525

26-
The following are Fiddler traces about how these cookies are set and used in a working flow:
26+
The following Fiddler traces describe how these cookies are set and used in a working flow:
2727

28-
1. In frame 116, the browser sends a request to the OIDC app protected by Microsoft Entra ID. After receiving the request, the app detects that it isn't authenticated and redirects it to Microsoft Entra ID (`login.microsoftonline.com`) for authentication. Additionally, the app sets the `OpenIdConnect.nonce` cookie in the 302 redirect response.
28+
- In Frame 116, the browser sends a request to the OIDC app that's protected by Microsoft Entra ID. After receiving the request, the app detects that it isn't authenticated. It then redirects the request to Microsoft Entra ID (`login.microsoftonline.com`) for authentication. Additionally, the app sets the `OpenIdConnect.nonce` cookie in the "302" redirect response.
2929

3030
:::image type="content" source="media/troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-start-auth.png" alt-text="Screenshot of Frame 116 in Fiddler Trace." lightbox="media/troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-start-auth.png":::
3131

32-
2. After successful authentication (frame 120228), Microsoft Entra ID redirects the request back to the web app (frame 229) with the authenticated ID token. The nonce cookie previously set for this domain is also included in the POST request. The OIDC middleware validates the authenticated token and the nonce cookie before it continues loading the page (via another redirect). At this point, the nonce cookie's purpose is complete, and the app invalidates it by setting the expiration attribute to expire.
32+
- After successful authentication (Frame 120228), Microsoft Entra ID redirects the request back to the web app (Frame 229) together with the authenticated ID token. The nonce cookie that was previously set for this domain is also included in the POST request. The OIDC middleware validates the authenticated token and the nonce cookie before it continues to load the page (through another redirect). At this point, the nonce cookie's purpose is finished, and the app invalidates it by setting the expiration attribute to expire.
3333

34-
:::image type="content" source="media/troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-after-auth.png" alt-text="Screenshot of Fiddler Trace Frames about authentication." lightbox="media/troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-after-auth.png":::
34+
:::image type="content" source="media/troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-after-auth.png" alt-text="Screenshot of Fiddler Trace Frames related to authentication." lightbox="media/troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-after-auth.png":::
3535

3636
## Solution
3737

3838
### Cause 1: Multiple domains are used for the same website
3939

40-
The browser originally navigates to the app on domain A (frame 9 below), and the nonce cookie is set for this domain. Later, Microsoft Entra ID sends the authenticated token to domain B (frame 91). Since the redirection to domain B doesn't include the nonce cookie, the web app throws the `validationContext.Nonce is null` error.
40+
The browser originally navigates to the app on Domain A (Frame 9), and the nonce cookie is set for this domain. Later, Microsoft Entra ID sends the authenticated token to Domain B (Frame 91). Because the redirection to Domain B doesn't include the nonce cookie, the web app throws the `validationContext.Nonce is null` error.
4141

42-
:::image type="content" source="media/troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-multiple-domains.png" alt-text="Screenshot of Fiddler Trace Frames about cause 1." lightbox="media/troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-multiple-domains.png":::
42+
:::image type="content" source="media/troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-multiple-domains.png" alt-text="Screenshot of Fiddler Trace Frames related to Cause 1." lightbox="media/troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-multiple-domains.png":::
4343

44-
#### Solution
44+
### Solution 1
4545

4646
To resolve this issue, follow these steps:
4747

48-
1. Redirect the request back to the same domain used originally after authentication. To control where Azure AD sent the authenticated request back to the app, set the `OpenIdConnectAuthentications.RedirectUri` property in the `ConfigureAuth` method.
48+
1. Redirect the request back to the same domain that was originally used after authentication. To control where Azure AD sent the authenticated request back to the app, set the `OpenIdConnectAuthentications.RedirectUri` property in the `ConfigureAuth` method.
4949

50-
1. Configure the redirect URI (reply URL) in App Registration, otherwise you may receive the following error: AADSTS50011: The reply url specified in the request doesn't match the reply urls configured for the app. For more information, see [Error AADSTS50011 with OpenID authentication](error-code-aadsts50011-redirect-uri-mismatch.md).
50+
1. Configure the redirect URI (reply URL) in App Registration. Otherwise you might receive the following error: AADSTS50011: The reply URL that's specified in the request doesn't match the reply URLs that Azure configured for the app. For more information, see [Error AADSTS50011 with OpenID authentication](error-code-aadsts50011-redirect-uri-mismatch.md).
5151

5252
### Cause 2: Missing SameSite attributes
5353

54-
Due to the [SameSite cookie security updates](/azure/active-directory/develop/howto-handle-samesite-cookie-changes-chrome-browser?tabs=dotnet), all cookies involved in the authentication process, including Nonce cookies, should contain the following attributes:
54+
Because of the [SameSite cookie security updates](/azure/active-directory/develop/howto-handle-samesite-cookie-changes-chrome-browser?tabs=dotnet), all cookies that are involved in the authentication process (including Nonce cookies) should contain the following attributes:
5555

5656
- SameSite=None
5757
- Secure
5858

5959
For more information, see [SameSite cookies and the Open Web Interface for .NET](/aspnet/samesite/owin-samesite).
6060

61-
![Screenshot of missing SameSite attributes Fiddler Trace.](./media//troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-misisng-samesite.png)
61+
![Screenshot of missing SameSite attributes Fiddler trace.](./media//troubleshoot-validation-context-nonce-null-mvc/fiddler-trace-misisng-samesite.png)
6262

63-
### Solution
63+
### Solution 2
6464

65-
To make sure both of the above requirements are satisfied, follow these steps:
65+
To make sure that both the required attributes are included, follow these steps:
6666

6767
1. Use the HTTPS protocol to navigate to the web app.
6868
1. Update .NET Framework and NuGet packages:
69-
- For .NET Framework apps: Upgrade .NET Framework to version 4.7.2+ and relevant NuGet packages (Microsoft.Owin.Security.OpenIdConnect, Microsoft.Owin) to version 4.1.0+.
69+
- For .NET Framework apps: Upgrade .NET Framework to version 4.7.2+ and relevant NuGet packages (Microsoft.Owin.Security.OpenIdConnect, Microsoft.Owin) to version 4.1.0+.
7070
- For .NET Core apps:
71-
- Version 2.x apps should use .NET Core 2.1+
72-
- Version 3.x apps should use .NET Core 3.1+
71+
- Version 2._x_ apps should use .NET Core 2.1+.
72+
- Version 3._x_ apps should use .NET Core 3.1+.
7373

7474
Example configuration code for Startup.Auth.cs:
7575

@@ -111,7 +111,7 @@ namespace NetWebAppOIDC2
111111
AuthenticationFailed = OnAuthenticationFailed
112112
}
113113

114-
// Don't use SystemwebCookieManager class here to override the default CookieManager as that seems to negate the SameSite cookie attribute being set
114+
// Don't use SystemwebCookieManager class here to override the default CookieManager because that seems to negate the SameSite cookie attribute that's being set.
115115
// CookieManager = new SystemWebCookieManager()
116116
117117
});

0 commit comments

Comments
 (0)