42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using IdentityServer.Application.Commands;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace IdentityServer.Api.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("identity")]
|
|
public class IdentityController : ControllerBase
|
|
{
|
|
private readonly IMediator _mediator;
|
|
|
|
public IdentityController(IMediator mediator)
|
|
{
|
|
_mediator = mediator;
|
|
}
|
|
|
|
[HttpPost("authenticate/{userName}/{password}")]
|
|
public async Task<IActionResult> AuthenticateUser([FromRoute] AuthenticateUser authenticateUser)
|
|
{
|
|
var result = await _mediator.Send(authenticateUser);
|
|
|
|
if (result != null)
|
|
return Ok(result);
|
|
else
|
|
return BadRequest();
|
|
}
|
|
|
|
[HttpPost("authorize/{token}")]
|
|
public async Task<IActionResult> AuthorizeToken([FromRoute] AuthorizeToken authorizeToken)
|
|
{
|
|
var result = await _mediator.Send(authorizeToken);
|
|
|
|
if (result != null)
|
|
return Ok(result);
|
|
else
|
|
return BadRequest();
|
|
}
|
|
}
|
|
}
|