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
| [HttpPost, AllowAnonymous, Route("register")] | |
| public async Task<IActionResult> CreateUser([FromBody] CreateUser command) | |
| { | |
| // ... conteúdo ocultado | |
| } | |
| [HttpPost, AllowAnonymous, Route("login")] | |
| public async Task<IActionResult> Authenticate([FromBody] AuthenticateUser command) | |
| { | |
| // ... conteúdo ocultado |
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
| public class Startup | |
| { | |
| // ... restante do arquivo ocultado | |
| public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | |
| { | |
| // .. restante do método ocultado | |
| app.UseAuthentication(); | |
| app.UseMvc(); |
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
| public void ConfigureServices(IServiceCollection services) | |
| { | |
| // ... restante do método ocultado | |
| services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); | |
| services.AddScoped<AuthenticatedUser>(); | |
| } |
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
| public class AuthenticatedUser | |
| { | |
| private readonly IHttpContextAccessor _accessor; | |
| public AuthenticatedUser(IHttpContextAccessor accessor) | |
| { | |
| _accessor = accessor; | |
| } | |
| public string Email => _accessor.HttpContext.User.Identity.Name; |
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
| [Route("api/[controller]"), Authorize(Roles = "Administrator")] | |
| public class AdministrationController : Controller | |
| { | |
| [HttpGet, Route("accounts")] | |
| public async Task<IActionResult> ListUsers() | |
| { | |
| // ... conteúdo omitido | |
| } | |
| } |
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
| [Route("api/[controller]")] | |
| public class AuthController : Controller | |
| { | |
| private readonly IMediator _mediator; | |
| public AuthController(IMediator mediator) | |
| { | |
| _mediator = mediator; | |
| } |
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
| public class AuthenticateUserHandler : IRequestHandler<AuthenticateUser, Response> | |
| { | |
| private readonly IJwtService _jwtService; | |
| private readonly IUserRepository _repository; | |
| public AuthenticateUserHandler(IJwtService jwtService, IUserRepository repository) | |
| { | |
| _jwtService = jwtService; | |
| _repository = repository; | |
| } |
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
| public class JwtService : IJwtService | |
| { | |
| private readonly JwtSettings _settings; | |
| public JwtService(JwtSettings settings) | |
| { | |
| _settings = settings; | |
| } | |
| public object CreateJwtToken(User user) |