aboutsummaryrefslogtreecommitdiff
path: root/backend/api
diff options
context:
space:
mode:
Diffstat (limited to 'backend/api')
-rw-r--r--backend/api/api/Controllers/AuthController.cs6
-rw-r--r--backend/api/api/Models/JwtToken.cs16
-rw-r--r--backend/api/api/Services/AuthService.cs5
-rw-r--r--backend/api/api/Services/IAuthService.cs1
4 files changed, 28 insertions, 0 deletions
diff --git a/backend/api/api/Controllers/AuthController.cs b/backend/api/api/Controllers/AuthController.cs
index 7167d1bf..901454e1 100644
--- a/backend/api/api/Controllers/AuthController.cs
+++ b/backend/api/api/Controllers/AuthController.cs
@@ -30,6 +30,12 @@ namespace api.Controllers
return Ok(_auth.Login(user));
}
+ [HttpPost("guestToken")]
+ public async Task<ActionResult<string>> guestToken()
+ {
+
+ return Ok(_auth.GuestToken());
+ }
[HttpGet("Auth")]
[Authorize(Roles ="User")]
diff --git a/backend/api/api/Models/JwtToken.cs b/backend/api/api/Models/JwtToken.cs
index a98d1967..f262fd23 100644
--- a/backend/api/api/Models/JwtToken.cs
+++ b/backend/api/api/Models/JwtToken.cs
@@ -69,6 +69,22 @@ namespace api.Models
}
+ public string GenGuestToken()
+ {
+ var tokenHandler = new JwtSecurityTokenHandler();
+ var key = Encoding.ASCII.GetBytes(_configuration.GetSection("AppSettings:JwtToken").Value);
+ var tokenDescriptor = new SecurityTokenDescriptor
+ {
+ Subject = new ClaimsIdentity(new[] { new Claim("name",""),
+ new Claim("role", "Guest")}),
+ Expires = DateTime.UtcNow.AddMinutes(20),
+ SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
+ };
+ var token = tokenHandler.CreateToken(tokenDescriptor);
+ return tokenHandler.WriteToken(token);
+
+ }
+
}
diff --git a/backend/api/api/Services/AuthService.cs b/backend/api/api/Services/AuthService.cs
index 4f838463..8ef96e2e 100644
--- a/backend/api/api/Services/AuthService.cs
+++ b/backend/api/api/Services/AuthService.cs
@@ -57,6 +57,11 @@ namespace api.Services
return null;
}
+ public string GuestToken()
+ {
+ return _jwt.GenGuestToken();
+ }
+
}
}
diff --git a/backend/api/api/Services/IAuthService.cs b/backend/api/api/Services/IAuthService.cs
index 591d122d..9a109208 100644
--- a/backend/api/api/Services/IAuthService.cs
+++ b/backend/api/api/Services/IAuthService.cs
@@ -7,5 +7,6 @@ namespace api.Services
string Login(AuthRequest user);
string Register(RegisterRequest user);
string RenewToken(string token);
+ public string GuestToken();
}
} \ No newline at end of file