title: Parsing JWT to get claims in C#
body: <p>Our senior developer wrote the following code, as an example:</p>
  
  <pre><code>public class TokenParser 
  {
      private Token token;
  
      public Token Parse(HttpRequestMessage r)
      {
          IOwinContext context = r.GetOwinContext();
          token = new Token();
          ParseData(context);
          return token;
      }
  
      private void ParseData(IOwinContext context)
      {
          token.Name= context.Authentication.User.Claims.Single(x =&gt; x.Type == ClaimTypes.Name).Value;
      }
  }
  </code></pre>
  
  <p>(There is also a "Token.cs" class that just has a name property as string.)</p>
  
  <p>Our <a href="http://jwt.io/" rel="noreferrer">decoded</a> JWT payload looks like this:</p>
  
  <pre><code>{
    "iss": "https://someissuer.com/",
    "sub": "I want this string, atm I get it manually",
    "aud": "11543fdsasf23432",
    "exp": 33244323433,
    "iat": 23443223434
  }
  </code></pre>
  
  <p>The problem I run into is that when I try to get claim by Type "sub", nothing comes up (and it's not in the list). BUT "sub" seems to be an <a href="https://scotch.io/tutorials/the-anatomy-of-a-json-web-token" rel="noreferrer">extremely common claim</a>.</p>
  
  <p>What am I doing wrong here? Go do I get the subject ("sub") claim? </p>
  
  <p>Edit: For those recommending system.IdentityModel - I get this error when trying to use it:</p>
  
  <p><img src="https://i.stack.imgur.com/pXNTz.png" alt="identityModelError"></p>