# IDX21323 RequireNonce error with webforms app

**URL:** <https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491>\
**Category:** Questions\
**Tags:** dotnet\
**Created:** [November 28, 2018, 10:56pm UTC](https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491 "2018-11-28T22:56:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tleonard](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/tleonard/32/754_2.png) [@tleonard](https://devforum.okta.com/u/tleonard)\
**Post date:** [November 28, 2018, 10:56pm UTC](https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491/1 "2018-11-28T22:56:22Z")

</div>

I saw [this thread](https://devforum.okta.com/t/idx21323-requirenonce-error/1370) from a few months back, but it had no actual answer, so I wanted to see if anyone else had run into this and knew what fixed it. Also I’m using the new Okta.AspNet library, which it isn’t clear the other poster had in place.

I’ve got an [ASP.NET](http://ASP.NET) WebForms app using Okta.AspNet 1.1.1 for auth handling. For the most part it works fine, except for the occasional error for the `/authorization-code/callback` URL:

```
Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectProtocolInvalidNonceException
IDX21323: RequireNonce is '[PII is hidden]'. 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.

```

Most times `AUTH_USER` is set, but occasionally not.

My `Startup` class’ `Configuration` function:

```
Public Sub Configuration(app As IAppBuilder)
    app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType)

    app.UseCookieAuthentication(New CookieAuthenticationOptions())

    Dim settingPrefix = EnvironmentSettingPrefix(app)
    Dim appSettings = ConfigurationManager.AppSettings

    Dim oktaPrefix = settingPrefix & OKTA_SETTING_PREFIX
    Dim options = New OktaMvcOptions With
        {
        .OktaDomain = appSettings.Item(oktaPrefix & "domain"),
        .ClientId = appSettings.Item(oktaPrefix & "clientId"),
        .ClientSecret = appSettings.Item(oktaPrefix & "clientSecret"),
        .RedirectUri = appSettings.Item(oktaPrefix & "redirectUri"),
        .PostLogoutRedirectUri = appSettings.Item(oktaPrefix & "postLogoutRedirectUri"),
        .AuthorizationServerId = appSettings.Item(oktaPrefix & "authorizationServerId"),
        .GetClaimsFromUserInfoEndpoint = True,
        .Scope = New List(Of String) From {"openid", "profile", "email"}
        }
    app.UseOktaMvc(options)
End Sub

```

That’s pretty much verbatim from the [Okta ASP.NET Quickstart](https://developer.okta.com/quickstart/#/okta-sign-in-page/dotnet/aspnet4) The other thread on this mentioned using `UseExternalSignInCookie`, but I’m new enough to [ASP.NET](http://ASP.NET) to not know why that’d be necessary, given logins work for the most part.

Thanks.

---

<div class="post-metadata">

**Author:** ![Immanuel79](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/immanuel79/32/1246_2.png) [@Immanuel79](https://devforum.okta.com/u/Immanuel79)\
**Post date:** [July 16, 2019, 6:16pm UTC](https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491/2 "2019-07-16T18:16:21Z")

</div>

I have the same problem - has anyone found a solution yet?

---

<div class="post-metadata">

**Author:** ![tleonard](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/tleonard/32/754_2.png) [@tleonard](https://devforum.okta.com/u/tleonard)\
**Post date:** [August 9, 2019, 3:05pm UTC](https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491/3 "2019-08-09T15:05:17Z")

</div>

My solution was something of a hack, but seems to have worked. In `Global.asax` I updated `Application_Error()` to notice these problems and “re-auth” the user so we get a proper nonce.

I’m not enamored with this, due to the potential for a redirect loop, but that doesn’t seem to have happened, checking our logs.

```auto
Dim ex = Server.GetLastError()

' We often see invalid nonce errors where user's the ID token has a nonce, but the validation context does not.
' This is a hack solution to hopefully fix that. We simply re-challenge the client, which should bounce them through auth and back with a proper nonce.
' It's possible this could end up in a redirect loop. If we start seeing errors to that effect, we should try to detect when we've done this once, and stop.
If TypeOf ex Is Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectProtocolInvalidNonceException Then
    Context.GetOwinContext().Authentication.Challenge()
    Exit Sub
End If

```

---

<div class="post-metadata">

**Author:** ![Immanuel79](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/immanuel79/32/1246_2.png) [@Immanuel79](https://devforum.okta.com/u/Immanuel79)\
**Post date:** [August 11, 2019, 12:12am UTC](https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491/4 "2019-08-11T00:12:01Z")

</div>

Thanks tleonard. I have achieved something similar using OWin Pipelines, but your post was the inspiration.

In my patch config file I added

```
  <sitecore>
    <pipelines>
      <owin.globalExceptionHandler>
        <processor type="MyProject.Authentication.Okta.Pipelines.ExceptionsHandler, MyProject.Authentication.Okta" resolve="true" />
      </owin.globalExceptionHandler>
    </pipelines>
  </sitecore>

```

And the class was implemented like so:

```
public class ExceptionsHandler : GlobalExceptionHandlerProcessor {
    public override void Process(GlobalExceptionHandlerArgs args) {
        Assert.ArgumentNotNull((object)args, nameof(args));
        string message = args.Exception.Message;
        var context = args.Context;

        if (message.StartsWith("IDX21323")) {
            args.Context.Response.Redirect("<where I need to>");
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![rcorkery](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@rcorkery](https://devforum.okta.com/u/rcorkery)\
**Post date:** [April 15, 2021, 6:16pm UTC](https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491/5 "2021-04-15T18:16:33Z")

</div>

@Immanuel79 or @tleonard have either of you come up with a better solution for this issue?

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [April 15, 2021, 6:31pm UTC](https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491/6 "2021-04-15T18:31:00Z")

</div>

samesite cookie issues may be to blame. Check out [this article](https://support.okta.com/help/s/article/Troubleshooting-IDX21323-RequireNonce-is-System-Boolean?language=en_US) and [this blog post](https://developer.okta.com/blog/2020/09/28/adapt-dotnet-app-for-samesite-fix) that breaks this down to see if that could be the cause here.

Another potential cause is if the OAuth flow is NOT getting kicked off by your .NET app (such as you manually redirecting a user to the /authorize endpoint with the redirect\_uri pointing back to your .NET apps’ callback route) and may be worth investigating as well. Your .NET application must handle this step itself, because that is when the nonce cookie gets set.

---

<div class="post-metadata">

**Author:** ![tleonard](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/tleonard/32/754_2.png) [@tleonard](https://devforum.okta.com/u/tleonard)\
**Post date:** [April 16, 2021, 1:37pm UTC](https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491/7 "2021-04-16T13:37:50Z")

</div>

Another dev ended up recreating the site in [ASP.NET](http://ASP.NET) Core. They tell me that haven’t seen any issues like this so far, so maybe some updated default or other code change fixed it.

Sorry I don’t have anything more specific.

---

<div class="post-metadata">

**Author:** ![rcorkery](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@rcorkery](https://devforum.okta.com/u/rcorkery)\
**Post date:** [April 22, 2021, 12:49am UTC](https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491/8 "2021-04-22T00:49:49Z")

</div>

@andrea Thanks for this information. However, I am not sure if the post in your first sentence is the same issue.

Here is the error message I am getting: IDX21323: RequireNonce is ‘[PII is hidden. For more details, see [https://aka.ms/IdentityModel/PII.]](https://aka.ms/IdentityModel/PII.%5D)’. 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.

The above is a different error message (slightly) then what the post mentions.

Based on the above error message, do you still think this is the same issue?

Also, I don’t understand your last suggestion. Could you be a little more specific in what I am looking for?

This is how I have the Redirect URI processing set up.

```
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Request.IsAuthenticated)
        {
            Context.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = ResolveUrl("~/SetCurrentUser.aspx") }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
        }
        else
        {
            Response.Redirect("~/Default.aspx", false);
        }
    }

```

Please let me know. Thanks!!!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [February 8, 2024, 6:05pm UTC](https://devforum.okta.com/t/idx21323-requirenonce-error-with-webforms-app/3491/9 "2024-02-08T18:05:10Z")

</div>

Closed on February 8, 2024, 6:05pm UTC

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
