From a9072370ca1eb9a5cce928b1d487db0f307edea6 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Tue, 20 Sep 2022 15:24:27 +0800 Subject: feat: Move old apps into it's own directory --- .../src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs | 86 +++++++++++----------- 1 file changed, 45 insertions(+), 41 deletions(-) (limited to 'server/src/Endpoints') diff --git a/server/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs b/server/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs index 352ad18..2086619 100644 --- a/server/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs +++ b/server/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs @@ -1,53 +1,57 @@ using System.Text; -using Microsoft.Extensions.Options; namespace IOL.GreatOffice.Api.Endpoints.V1.ApiTokens; public class CreateTokenRoute : RouteBaseSync.WithRequest.WithActionResult { - private readonly AppDbContext _context; - private readonly AppConfiguration _configuration; - private readonly ILogger _logger; + private readonly AppDbContext _context; + private readonly AppConfiguration _configuration; + private readonly ILogger _logger; - public CreateTokenRoute(AppDbContext context, VaultService vaultService, ILogger logger) { - _context = context; - _configuration = vaultService.GetCurrentAppConfiguration(); - _logger = logger; - } + public CreateTokenRoute(AppDbContext context, VaultService vaultService, ILogger logger) + { + _context = context; + _configuration = vaultService.GetCurrentAppConfiguration(); + _logger = logger; + } - /// - /// Create a new api token with the provided claims. - /// - /// The claims to set on the api token - /// - [ApiVersion(ApiSpecV1.VERSION_STRING)] - [HttpPost("~/v{version:apiVersion}/api-tokens/create")] - [ProducesResponseType(200, Type = typeof(string))] - [ProducesResponseType(404, Type = typeof(ErrorResult))] - public override ActionResult Handle(ApiAccessToken.ApiAccessTokenDto request) { - var user = _context.Users.SingleOrDefault(c => c.Id == LoggedInUser.Id); - if (user == default) { - return NotFound(new ErrorResult("User does not exist")); - } + /// + /// Create a new api token with the provided claims. + /// + /// The claims to set on the api token + /// + [ApiVersion(ApiSpecV1.VERSION_STRING)] + [HttpPost("~/v{version:apiVersion}/api-tokens/create")] + [ProducesResponseType(200, Type = typeof(string))] + [ProducesResponseType(404, Type = typeof(ErrorResult))] + public override ActionResult Handle(ApiAccessToken.ApiAccessTokenDto request) + { + var user = _context.Users.SingleOrDefault(c => c.Id == LoggedInUser.Id); + if (user == default) + { + return NotFound(new ErrorResult("User does not exist")); + } - var token_entropy = _configuration.APP_AES_KEY; - if (token_entropy.IsNullOrWhiteSpace()) { - _logger.LogWarning("No token entropy is available, Basic auth is disabled"); - return NotFound(); - } + var token_entropy = _configuration.APP_AES_KEY; + if (token_entropy.IsNullOrWhiteSpace()) + { + _logger.LogWarning("No token entropy is available, Basic auth is disabled"); + return NotFound(); + } - var access_token = new ApiAccessToken() { - Id = Guid.NewGuid(), - User = user, - ExpiryDate = request.ExpiryDate.ToUniversalTime(), - AllowCreate = request.AllowCreate, - AllowRead = request.AllowRead, - AllowDelete = request.AllowDelete, - AllowUpdate = request.AllowUpdate - }; + var access_token = new ApiAccessToken() + { + Id = Guid.NewGuid(), + User = user, + ExpiryDate = request.ExpiryDate.ToUniversalTime(), + AllowCreate = request.AllowCreate, + AllowRead = request.AllowRead, + AllowDelete = request.AllowDelete, + AllowUpdate = request.AllowUpdate + }; - _context.AccessTokens.Add(access_token); - _context.SaveChanges(); - return Ok(Convert.ToBase64String(Encoding.UTF8.GetBytes(access_token.Id.ToString().EncryptWithAes(token_entropy)))); - } + _context.AccessTokens.Add(access_token); + _context.SaveChanges(); + return Ok(Convert.ToBase64String(Encoding.UTF8.GetBytes(access_token.Id.ToString().EncryptWithAes(token_entropy)))); + } } -- cgit v1.3