Build auth API
This commit is contained in:
commit
dafe603a06
43 changed files with 1153 additions and 0 deletions
35
src/Robware.Api.Auth/Controllers/AuthController.cs
Normal file
35
src/Robware.Api.Auth/Controllers/AuthController.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Robware.Api.Auth.Models;
|
||||
using Robware.Auth;
|
||||
|
||||
namespace Robware.Api.Auth.Controllers {
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class AuthController : ControllerBase {
|
||||
private readonly ILogger<AuthController> _logger;
|
||||
private readonly IAuthenticator _authenticator;
|
||||
|
||||
public AuthController(ILogger<AuthController> logger, IAuthenticator authenticator) {
|
||||
_logger = logger;
|
||||
_authenticator = authenticator;
|
||||
}
|
||||
|
||||
[HttpPost(nameof(Authenticate))]
|
||||
public async Task<ActionResult<User>> Authenticate(LoginRequest request) {
|
||||
var (result, user) = await _authenticator.Authenticate(request.Username, request.Password);
|
||||
switch (result) {
|
||||
case AuthenticationResult.Success:
|
||||
return user;
|
||||
case AuthenticationResult.NotFound:
|
||||
return NotFound();
|
||||
case AuthenticationResult.IncorrectPassword:
|
||||
return Unauthorized();
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue