protected override async Task <AuthenticateResult> HandleAuthenticateAsync() { if (Context.Request.Path != "/api/IsAlive" || Context.Request.Method != "GET") { if (!Context.Request.Headers.TryGetValue(KeyAuthOptions.DefaultHeaderName, out var headerValue)) { return(AuthenticateResult.Fail("No api key header.")); } var apiKey = headerValue.First(); if (!_apiKeyService.ValidateKey(apiKey)) { return(AuthenticateResult.Fail("Invalid API key.")); } } var identity = new ClaimsIdentity("apikey"); var ticket = new AuthenticationTicket(new ClaimsPrincipal(identity), null, "apikey"); return(await Task.FromResult(AuthenticateResult.Success(ticket))); }