aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/API/Controllers/SessionController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/slskd/API/Controllers/SessionController.cs')
-rw-r--r--src/slskd/API/Controllers/SessionController.cs70
1 files changed, 42 insertions, 28 deletions
diff --git a/src/slskd/API/Controllers/SessionController.cs b/src/slskd/API/Controllers/SessionController.cs
index d5b2c81a..c6b564de 100644
--- a/src/slskd/API/Controllers/SessionController.cs
+++ b/src/slskd/API/Controllers/SessionController.cs
@@ -1,20 +1,36 @@
-using Microsoft.Extensions.Options;
+// <copyright file="SessionController.cs" company="slskd Team">
+// Copyright (c) slskd Team. All rights reserved.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see https://www.gnu.org/licenses/.
+// </copyright>
+
+using Microsoft.Extensions.Options;
namespace slskd.API.Controllers
{
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
- using slskd.API.DTO;
+ using Microsoft.AspNetCore.Authorization;
+ using Microsoft.AspNetCore.Mvc;
+ using Microsoft.IdentityModel.Tokens;
using slskd;
- using slskd.Configuration;
+ using slskd.API.DTO;
/// <summary>
- /// Session
+ /// Session.
/// </summary>
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("0")]
@@ -23,9 +39,6 @@ namespace slskd.API.Controllers
[Consumes("application/json")]
public class SessionController : ControllerBase
{
- private Options Options { get; set; }
- private SymmetricSecurityKey JwtSigningKey { get; set; }
-
public SessionController(
IOptionsSnapshot<Options> optionsSnapshot,
SymmetricSecurityKey jwtSigningKey)
@@ -34,26 +47,13 @@ namespace slskd.API.Controllers
JwtSigningKey = jwtSigningKey;
}
- /// <summary>
- /// Checks whether security is enabled.
- /// </summary>
- /// <returns></returns>
- /// <response code="200">True if security is enabled, false otherwise.</response>
- [HttpGet]
- [Route("enabled")]
- [AllowAnonymous]
- [ProducesResponseType(typeof(bool), 200)]
- public IActionResult Enabled()
- {
- return base.Ok(!Options.Web.Authentication.Disable);
- }
+ private SymmetricSecurityKey JwtSigningKey { get; set; }
+ private Options Options { get; set; }
/// <summary>
/// Checks whether the provided authentication is valid.
/// </summary>
- /// <remarks>
- /// This is a no-op provided so that the application can test for an expired token on load.
- /// </remarks>
+ /// <remarks>This is a no-op provided so that the application can test for an expired token on load.</remarks>
/// <returns></returns>
/// <response code="200">The authentication is valid.</response>
/// <response code="403">The authentication is is invalid.</response>
@@ -68,6 +68,20 @@ namespace slskd.API.Controllers
}
/// <summary>
+ /// Checks whether security is enabled.
+ /// </summary>
+ /// <returns></returns>
+ /// <response code="200">True if security is enabled, false otherwise.</response>
+ [HttpGet]
+ [Route("enabled")]
+ [AllowAnonymous]
+ [ProducesResponseType(typeof(bool), 200)]
+ public IActionResult Enabled()
+ {
+ return base.Ok(!Options.Web.Authentication.Disable);
+ }
+
+ /// <summary>
/// Logs in.
/// </summary>
/// <param name="login"></param>
@@ -114,7 +128,7 @@ namespace slskd.API.Controllers
new Claim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString()),
new Claim(ClaimTypes.Role, role.ToString()),
new Claim("name", username),
- new Claim("iat", ((DateTimeOffset)issuedUtc).ToUnixTimeSeconds().ToString())
+ new Claim("iat", ((DateTimeOffset)issuedUtc).ToUnixTimeSeconds().ToString()),
};
var credentials = new SigningCredentials(JwtSigningKey, SecurityAlgorithms.HmacSha256);
@@ -129,4 +143,4 @@ namespace slskd.API.Controllers
return token;
}
}
-}
+} \ No newline at end of file