protected override Task <AuthenticateResult> HandleAuthenticateAsync() { // Get Authorization header value if (!Request.Headers.TryGetValue(HeaderNames.Authorization, out var authorization)) { return(Task.FromResult(AuthenticateResult.Fail("Cannot read authorization header!"))); } // The auth key from Authorization header check against the configured ones if (!_usersClient.GetTokenCorrectness(authorization).Result) { return(Task.FromResult(AuthenticateResult.Fail("Invalid token!"))); } // To delete scheme string token = authorization.ToString().Substring(7); var jwtClaims = new JwtSecurityTokenHandler().ReadJwtToken(token).Claims; // Create authenticated user var claims = new[] { new Claim("Player", "Player"), jwtClaims.First(c => c.Type == "id") }; var identities = new[] { new ClaimsIdentity(claims) }; var ticket = new AuthenticationTicket(new ClaimsPrincipal(identities), Options.Scheme); return(Task.FromResult(AuthenticateResult.Success(ticket))); }