From 571f99876be90121c0cfa882d50c8a901d1635a6 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 17 May 2021 09:11:26 -0500 Subject: fix warnings --- src/slskd/API/Controllers/SessionController.cs | 70 +++++++++++++++----------- 1 file changed, 42 insertions(+), 28 deletions(-) (limited to 'src/slskd/API/Controllers/SessionController.cs') 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 (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/. +// + +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; /// - /// Session + /// Session. /// [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 optionsSnapshot, SymmetricSecurityKey jwtSigningKey) @@ -34,26 +47,13 @@ namespace slskd.API.Controllers JwtSigningKey = jwtSigningKey; } - /// - /// Checks whether security is enabled. - /// - /// - /// True if security is enabled, false otherwise. - [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; } /// /// Checks whether the provided authentication is valid. /// - /// - /// This is a no-op provided so that the application can test for an expired token on load. - /// + /// This is a no-op provided so that the application can test for an expired token on load. /// /// The authentication is valid. /// The authentication is is invalid. @@ -67,6 +67,20 @@ namespace slskd.API.Controllers return Ok(); } + /// + /// Checks whether security is enabled. + /// + /// + /// True if security is enabled, false otherwise. + [HttpGet] + [Route("enabled")] + [AllowAnonymous] + [ProducesResponseType(typeof(bool), 200)] + public IActionResult Enabled() + { + return base.Ok(!Options.Web.Authentication.Disable); + } + /// /// Logs in. /// @@ -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 -- cgit v1.2.3