aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Controllers/SessionController.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-01-30 16:51:00 -0600
committerJP Dillingham <jpdillingham@gmail.com>2021-01-30 16:51:00 -0600
commit5a139833a9187db3cbf345e3899a9b81fbc969d6 (patch)
tree4428077e45c7409a68fbf108873f3364aebe7930 /src/slskd/Controllers/SessionController.cs
parentae0d355d117e80506ec2f4f52c57b8805aa16d5e (diff)
downloadslskd-5a139833a9187db3cbf345e3899a9b81fbc969d6.tar.gz
use default auth only (for now)
Diffstat (limited to 'src/slskd/Controllers/SessionController.cs')
-rw-r--r--src/slskd/Controllers/SessionController.cs31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/slskd/Controllers/SessionController.cs b/src/slskd/Controllers/SessionController.cs
index c0f17645..92e182d0 100644
--- a/src/slskd/Controllers/SessionController.cs
+++ b/src/slskd/Controllers/SessionController.cs
@@ -9,8 +9,8 @@
using System.Security.Claims;
using slskd.DTO;
using Microsoft.Extensions.Options;
- using System.Linq;
using slskd;
+ using System.Text.Json;
/// <summary>
/// Session
@@ -22,17 +22,15 @@
[Consumes("application/json")]
public class SessionController : ControllerBase
{
- private IOptionsSnapshot<Configuration.Program> SoulseekOptions { get; set; }
- private IOptionsSnapshot<Configuration.Authentication> AuthenticationOptions { get; set; }
+ private slskd.Options Options { get; set; }
private SymmetricSecurityKey JwtSigningKey { get; set; }
public SessionController(
- IOptionsSnapshot<Configuration.Program> soulseekOptions,
- IOptionsSnapshot<Configuration.Authentication> authenticationOptions,
+ IOptionsSnapshot<slskd.Options> optionsSnapshot,
SymmetricSecurityKey jwtSigningKey)
{
- SoulseekOptions = soulseekOptions;
- AuthenticationOptions = authenticationOptions;
+ Options = optionsSnapshot.Value;
+ Console.WriteLine(JsonSerializer.Serialize(Options));
JwtSigningKey = jwtSigningKey;
}
@@ -47,7 +45,7 @@
[ProducesResponseType(typeof(bool), 200)]
public IActionResult Enabled()
{
- return base.Ok((object)!Program.Options.NoAuth);
+ return base.Ok(!Options.Web.NoAuth);
}
/// <summary>
@@ -96,19 +94,10 @@
return BadRequest("Username and/or Password missing or invalid");
}
- var user = AuthenticationOptions.Value.Users
- .Where(u => u.Name == login.Username)
- .FirstOrDefault();
-
- // todo: allow login with root creds
- if (user == default)
- {
- return Unauthorized();
- }
-
- if (login.Password == user.Password)
+ // only admin login for now
+ if (Options.Username == login.Username && Options.Password == login.Password)
{
- return Ok(new TokenResponse(GetJwtSecurityToken(user.Name, user.Role)));
+ return Ok(new TokenResponse(GetJwtSecurityToken(login.Username, Role.Administrator)));
}
return Unauthorized();
@@ -117,7 +106,7 @@
private JwtSecurityToken GetJwtSecurityToken(string username, Role role)
{
var issuedUtc = DateTime.UtcNow;
- var expiresUtc = DateTime.UtcNow.AddMilliseconds((double)Program.Options.Web.Jwt.TTL);
+ var expiresUtc = DateTime.UtcNow.AddMilliseconds(Options.Web.Jwt.Ttl);
var claims = new List<Claim>()
{