title: Get claims from JWT token in ASP.NET Core 2.0 API
body: <p>I'm using mixed authentication in my ASP.NET Core 2.0 Web and API app. Meaning both cookies and now adding <code>JWT token</code>.</p>
  
  <p>The web part of the app uses cookies and in the API part, I want to use JWT token.</p>
  
  <p>My question is how do I get the claims from <code>JWT token</code>? In my web controllers, I can simply use <code>HttpContext.User;</code> to get the claims stored in a cookie. How do I handle it in my API methods where I want to use <code>JWT token</code>?</p>
  
  <p>Here's my AuthenticationBuilder: </p>
  
  <pre><code>public static void MyAuthenticationConfig(IServiceCollection services, IConfiguration configuration)
  {
     services.AddAuthentication(options =&gt;
     {
        options.DefaultAuthenticateScheme = "myApp_cookie";
        options.DefaultChallengeScheme = "myApp_cookie";
      })
      .AddCookie("myApp_cookie", options =&gt;
      {
        options.AccessDeniedPath = "/Unauthorized";
        options.LoginPath = "/Login";
      })
      .AddCookie("social_auth_cookie")
      .AddOAuth("LinkedIn", options =&gt;
      {
        options.SignInScheme = "social_auth_cookie";
  
        options.ClientId = "my_client_id";
        options.ClientSecret = "my_secret";
  
        options.CallbackPath = "/linkedin-callback";
  
        options.AuthorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization";
        options.TokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken";
        options.UserInformationEndpoint = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,picture-urls::(original))";
  
        options.Scope.Add("r_basicprofile");
        options.Scope.Add("r_emailaddress");
  
        options.Events = new OAuthEvents
        {
           OnCreatingTicket = OnCreatingTicketLinkedInCallBack,
           OnTicketReceived = OnTicketReceivedCallback
         };
      })
      .AddFacebook(options =&gt;
      {
          options.SignInScheme = "social_auth_cookie";
          options.AppId = "my_app_is";
          options.AppSecret = "my_secret";
          options.Events = new OAuthEvents
          {
             OnCreatingTicket = OnCreatingTicketFacebookCallback,
             OnTicketReceived = OnTicketReceivedCallback
           };
       })
       .AddGoogle(options =&gt;
       {
           options.SignInScheme = "social_auth_cookie";
           options.ClientId = "my_id.apps.googleusercontent.com";
           options.ClientSecret = "my_secret";
           options.CallbackPath = "/google-callback";
           options.Events = new OAuthEvents
           {
               OnCreatingTicket = OnCreatingTicketGoogleCallback,
               OnTicketReceived = OnTicketReceivedCallback
           };
        })
        .AddJwtBearer("JwtBearer", jwtBearerOptions =&gt;
        {
           jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters
           {
               ValidateIssuerSigningKey = true,
               IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("my_secret")),
  
               ValidateIssuer = true,
               ValidIssuer = "my-api",
  
               ValidateAudience = true,
               ValidAudience = "my-client",
  
               ValidateLifetime = true,
  
               ClockSkew = TimeSpan.FromMinutes(5)
          };
      });
  }
  </code></pre>