title: How to set TokenValidationParameters.NameClaimType to "username" instead of "name" for Azure AD B2C user?
body: <p>I have the following code to configure the process of authentication in my ASP.NET MVC web application, including the setting a claim to the user's "name" when validating the user's identity token received by the application.</p>
  
  <p>(Note that I am following <a href="https://github.com/Azure-Samples/active-directory-b2c-dotnet-webapp-and-webapi/blob/master/TaskWebApp/App_Start/Startup.Auth.cs" rel="nofollow noreferrer">this sample code</a>)</p>
  
  <pre><code>public void ConfigureAuth(IAppBuilder app)
  {
      app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
  
      app.UseCookieAuthentication(new CookieAuthenticationOptions()
      {
          CookieSecure = CookieSecureOption.Always
      });
  
      app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
      {
          // Generate the metadata address using the tenant and policy information
          MetadataAddress = String.Format(AadInstance, Tenant, DefaultPolicy),
  
              // These are standard OpenID Connect parameters, with values pulled from web.config
              ClientId = ClientId,
              Authority = Authority,
              PostLogoutRedirectUri = RedirectUri,
              RedirectUri = RedirectUri,
  
              Notifications = new OpenIdConnectAuthenticationNotifications()
              {
                  RedirectToIdentityProvider = OnRedirectToIdentityProvider,
                  AuthenticationFailed = OnAuthenticationFailed,
                  AuthorizationCodeReceived = OnAuthorizationCodeReceived,
              },
  
              // Specify the claims to validate
              TokenValidationParameters = new TokenValidationParameters
              {
                  NameClaimType = "name"
              },
  
              // Specify the scope by appending all of the scopes requested into one string (separated by a blank space)
              Scope = $"{OpenIdConnectScopes.OpenId} {ReadTasksScope} {WriteTasksScope}"
      });
  }
  </code></pre>
  
  <p>The "name" claim type maps to the user's <code>DisplayName</code>, which is returned when I use the code <code>User.Identity.Name</code>.</p>
  
  <p><strong>How can I get <code>User.Identity.Name</code> to map to the user's Username, like in the below screenshot of an Azure Active Directory B2C user?</strong></p>
  
  <p><a href="https://i.stack.imgur.com/1KVpV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1KVpV.jpg" alt="enter image description here"></a></p>