Add APIKey authentication

This commit is contained in:
2023-11-22 20:53:06 -05:00
parent 38c3895459
commit 15f8385005
10 changed files with 179 additions and 26 deletions

View File

@@ -0,0 +1,20 @@
namespace TodoApi.Helpers
{
public interface IApiKeyValidator
{
bool Validate(string? apiKey);
}
public class ApiKeyValidator(List<string>? apiKeys) : IApiKeyValidator
{
private readonly List<string>? _apiKeys = apiKeys;
public bool Validate(string? apiKey)
{
if (_apiKeys == null) return false;
// Verify the provided apiKey is in our configuration
return _apiKeys.Contains(apiKey!.ToLower());
}
}
}