public async Task Invoke(HttpContext context) { var apiConfigurationkey = _configuration["Authorization"] ?? string.Empty; if (string.IsNullOrEmpty(apiConfigurationkey)) { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; await context.Response.WriteAsync("API Authentication Key is missing from the config"); return; } var authenticationData = _authHelper.ExtractAuthenticationDataFromContext(context); if (string.IsNullOrEmpty(authenticationData.AuthenticationKey)) { context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; await context.Response.WriteAsync("API Authentication Key is either missing or wrong."); return; } if (authenticationData.AuthenticationKey != apiConfigurationkey) { try { _authHelper.CheckVersionIsProvided(authenticationData); } catch (AuthorizationException) { context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; await context.Response.WriteAsync("API Authentication Key is either missing or wrong-"); return; } context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; await context.Response.WriteAsync("API Authentication Key is either missing or wrong."); return; } await _next.Invoke(context); }