Provide mechanism to validate API keys. Re-organise structure to reflect new responsibility
This commit is contained in:
parent
87ae65316f
commit
9519bc623b
27 changed files with 245 additions and 36 deletions
22
src/Robware.Auth/API/ApiKeyValidator.cs
Normal file
22
src/Robware.Auth/API/ApiKeyValidator.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Robware.Auth.API {
|
||||
public class ApiKeyValidator : IApiKeyValidator {
|
||||
private readonly IApiKeys _apiKeys;
|
||||
|
||||
public ApiKeyValidator(IApiKeys apiKeys) {
|
||||
_apiKeys = apiKeys;
|
||||
}
|
||||
|
||||
public async Task<bool> Validate(string key) {
|
||||
try {
|
||||
var apiKey = await _apiKeys.Get(key);
|
||||
return apiKey.Enabled;
|
||||
}
|
||||
catch (ApiKeyNotFoundException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue