Exemple #1
0
        private bool IsKeyValid(HttpContext httpContext)
        {
            if (!httpContext.Request.Query.ContainsKey("key"))
            {
                LogInvalidKey(httpContext, "no key was given.");
                return(false);
            }

            var keyValue = httpContext.Request.Query["key"];

            if (!Guid.TryParse(keyValue, out var key))
            {
                LogInvalidKey(httpContext, $"provided key '{keyValue}' is not a guid.");
                return(false);
            }

            var matchedKey = keyCollection.FirstOrDefault(k => k.Key == key);

            if (matchedKey == null)
            {
                LogInvalidKey(httpContext, $"provided key '{key}' is not valid.");
                return(false);
            }

            if (matchedKey.Revoked)
            {
                LogInvalidKey(httpContext, $"provided key '{key}' has been revoked.");
            }

            logger.LogInformation($"Request for '{httpContext.Request.Path}' was accepted with key '{key}'.");
            return(true);
        }