21 lines
504 B
C#
21 lines
504 B
C#
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());
|
|
}
|
|
}
|
|
}
|