Load api keys from database. Create api keys.
This commit is contained in:
parent
3331775a0b
commit
8718d81f7a
4 changed files with 61 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Robware.Auth.API;
|
||||
|
@ -9,13 +10,19 @@ namespace Robware.Api.Auth.Controllers {
|
|||
public class ApiController : ControllerBase {
|
||||
private readonly ILogger<ApiController> _logger;
|
||||
private readonly IApiKeyValidator _apiKeyValidator;
|
||||
private readonly IApiKeys _apiKeyRepository;
|
||||
|
||||
public ApiController(ILogger<ApiController> logger, IApiKeyValidator apiKeyValidator) {
|
||||
public ApiController(ILogger<ApiController> logger, IApiKeyValidator apiKeyValidator, IApiKeys apiKeyRepository) {
|
||||
_logger = logger;
|
||||
_apiKeyValidator = apiKeyValidator;
|
||||
_apiKeyRepository = apiKeyRepository;
|
||||
}
|
||||
|
||||
[HttpGet(nameof(Validate))]
|
||||
public async Task<ActionResult> Validate(string key) => await _apiKeyValidator.Validate(key) ? (ActionResult) Ok() : Unauthorized();
|
||||
|
||||
[HttpPost(nameof(Create))]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<ApiKey>> Create(string name) => await _apiKeyRepository.Create(name);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue