title: How to get Name of Authenticated user in ASP.NET Core application using Azure Active Directory
body: <p>In a ASP.NET Core application with Azure AD Connected and Configured. I am able to get the NameIdentifier using this code:</p>
  
  <pre><code>var user = User.FindFirst(ClaimTypes.NameIdentifier).Value; ✔️
  </code></pre>
  
  <p>When trying to get just a name with the following line of code:</p>
  
  <pre><code>var user = User.FindFirst(ClaimTypes.Name).Value; ❌
  </code></pre>
  
  <p>I receive the following error:</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>Looked up in Azure Active Directory the user does have a full first and last name. Tried many examples online, it looks like the name should be showing.</p>
  
  <p>UPDATE:</p>
  
  <p>Finally figured it out, at first I managed to get all the human readable text like this:</p>
  
  <pre><code>foreach (Claim item in User.Claims)
  {
      if (item.Type.Contains("name"))
      {
        var username = item.Value;
      }
  }
  </code></pre>
  
  <p>this is much better</p>
  
  <pre><code>var userName = User.FindFirst("name").Value;
  </code></pre>