title: Jwt token always return 401 .net core 3.1 web api
body: <p>I'm new at the Jwt. I create new web api running on 3.1 version and my configuration like that ;</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
          {
              services.AddControllers();
              JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
              var symmetricKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("mysupersecretkeytosharewithnooneandalwaysinsideapp"));
              TokenValidationParameters tokenValidationParameters = new TokenValidationParameters
              {
                  ValidIssuer = "Management",
                  ValidateIssuer = true,
                  ValidAudience = "Management",
                  ValidateAudience = true,
                  ValidateLifetime = true,
                  IssuerSigningKey = symmetricKey,
                  ValidateIssuerSigningKey = true,
              };
              services.AddCors();
              services.AddAuthentication(options =&gt;
              {
                  options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                  options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
                  options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
              }).AddJwtBearer(options =&gt;
              {
                  options.RequireHttpsMetadata = false;
                  options.SaveToken = true;
                  options.TokenValidationParameters = tokenValidationParameters;
              });
              services.AddHttpContextAccessor();
          }
  
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
  
              app.UseRouting();
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              app.UseCors(q =&gt; q.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
              app.UseAuthentication();
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllers();
              });
          }
  </code></pre>
  
  <p>And my token generator class like that ;</p>
  
  <pre><code>        public static string GenerateToken(string jwtKey, string jwtExpireMinutes)
          {
              var claims = new List&lt;Claim&gt;()
              {
                  new Claim(ClaimTypes.NameIdentifier,"C280298D-D896-49E2-96AD-5C82243F9048"),
                  new Claim(ClaimTypes.Email,"mfa@gmail.com"),
              };
              var keyByte = Encoding.UTF8.GetBytes(jwtKey);
              var signInKey = new SymmetricSecurityKey(keyByte);
              var expireMinutes = DateTime.Now.AddMinutes(Convert.ToDouble(jwtExpireMinutes));
              var token = new JwtSecurityToken(claims: claims, expires: expireMinutes, signingCredentials: new SigningCredentials(signInKey, SecurityAlgorithms.HmacSha256));
  
              return new JwtSecurityTokenHandler().WriteToken(token);
  
          }
  </code></pre>
  
  <p>I tried on Postman and I'm getting token successfuly but with this token When I call my method it returns 401 unauthorized.</p>
  
  <p>Controller has these attributes ;</p>
  
  <pre><code>    [ApiController]
      [Route("api/[controller]")]
      [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
  </code></pre>
  
  <p>These are the results ;</p>
  
  <p><a href="https://i.stack.imgur.com/helAF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/helAF.png" alt="Successfuly token"></a></p>
  
  <p><a href="https://i.stack.imgur.com/HLm4G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HLm4G.png" alt="401 Unauthorized"></a></p>