blob: 901454e1ccd7012f8f3a7f2ffe3a281f3fc452ac (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
using api.Models.Users;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using api.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Net.Http.Headers;
namespace api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AuthController : ControllerBase
{
private IAuthService _auth;
public AuthController(IAuthService auth)
{
_auth = auth;
}
[HttpPost("register")]
public async Task<ActionResult<string>> Register(RegisterRequest user)
{
return Ok(_auth.Register(user));
}
[HttpPost("login")]
public async Task<ActionResult<string>> Login(AuthRequest user)
{
return Ok(_auth.Login(user));
}
[HttpPost("guestToken")]
public async Task<ActionResult<string>> guestToken()
{
return Ok(_auth.GuestToken());
}
[HttpGet("Auth")]
[Authorize(Roles ="User")]
public async Task<ActionResult<string>> TestAuth()
{
return Ok("works");
}
[HttpPost("renewJwt")]
[Authorize(Roles = "User")]
public async Task<ActionResult<string>> RenewJwt() {
var authorization = Request.Headers[HeaderNames.Authorization];
var newToken=_auth.RenewToken(authorization);
if(newToken== null)
return BadRequest();
return Ok(newToken);
}
}
}
|