Created
May 17, 2019 12:38
-
-
Save vmandic/31f9956bcb8407644a61e5c001801c30 to your computer and use it in GitHub Desktop.
med-processor, part/4, snippet #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MedsProcessor.WebAPI.Infrastructure; | |
using Microsoft.AspNetCore.Authorization; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Mvc; | |
namespace MedsProcessor.WebAPI.Controllers | |
{ | |
[ApiVersionNeutral, Route("api/[controller]")] | |
public class AuthController : ApiControllerBase | |
{ | |
private readonly IJwtAuthService jwtService; | |
public AuthController(IJwtAuthService jwtService) | |
{ | |
this.jwtService = jwtService; | |
} | |
[AllowAnonymous, HttpPost("token")] | |
public ActionResult<AuthTokenResponse> RequestToken([FromBody] AuthTokenRequest request) | |
{ | |
var(authenticatedSuccessfully, token) = jwtService.IssueToken(request); | |
return authenticatedSuccessfully | |
? ApiResponse.ForData( | |
new AuthTokenResponse(token), | |
message: "Access token issued successfully.") | |
: ApiResponse.ForData( | |
new AuthTokenResponse(), | |
StatusCodes.Status401Unauthorized, | |
message: "An invalid or unauthorized Client ID was provided."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment