title: Retrieve claims from JWT authentication on ASP.NET Core MVC
body: <p>I have inherited an ASP.NET Core 5 MVC application that has integrated the authentication of the users with a third-party identity server, WSO2.</p>
  <p>The authentication is working fine, but I'm not able to understand how to retrieve the username of the user that has logged in.</p>
  <p>Here is the code:</p>
  <p>Startup.cs</p>
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddSession();
      services.AddControllersWithViews();
      services.AddTransient&lt;IUserRepository, UserRepository&gt;();
      services.AddTransient&lt;ITokenService, TokenService&gt;();
  
      services.AddAuthentication(auth =&gt;
      {
          auth.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
          //auth.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
      })
      .AddJwtBearer(options =&gt;
      {
          options.TokenValidationParameters = new TokenValidationParameters
          {
              ValidateIssuer = true,
              ValidateAudience = true,
              ValidateLifetime = true,
              ValidateIssuerSigningKey = true,
              ValidIssuer = Configuration[&quot;Jwt:Issuer&quot;],
              ValidAudience = Configuration[&quot;Jwt:Issuer&quot;],
              IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration[&quot;Jwt:Key&quot;]))
          };
      });
  
      services.AddHttpClient();
  }
  
  </code></pre>
  <p>in the controller I have added:</p>
  <pre><code>[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = &quot;Administrator,Supervisor&quot;)]
  
  </code></pre>