diff options
| author | ivar <i@oiee.no> | 2023-11-12 00:01:31 +0100 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2023-11-12 00:01:31 +0100 |
| commit | a9f9650400ed9e7f40db5ec5fd08a861f4c30902 (patch) | |
| tree | 7df4e6a086acc21a5b47b4fae8bf395f79061f29 /code/api/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs | |
| parent | 854dedead3a3ed987997a0132f527db73b65b0ac (diff) | |
| download | greatoffice-a9f9650400ed9e7f40db5ec5fd08a861f4c30902.tar.xz greatoffice-a9f9650400ed9e7f40db5ec5fd08a861f4c30902.zip | |
Change how config is operated
Diffstat (limited to 'code/api/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs')
| -rw-r--r-- | code/api/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/code/api/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs b/code/api/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs index 163ddb6..c28f534 100644 --- a/code/api/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs +++ b/code/api/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs @@ -5,12 +5,11 @@ namespace IOL.GreatOffice.Api.Endpoints.V1.ApiTokens; public class CreateTokenRoute : RouteBaseSync.WithRequest<CreateTokenRoute.Payload>.WithActionResult { private readonly MainAppDatabase _database; - private readonly AppConfiguration _configuration; private readonly ILogger<CreateTokenRoute> _logger; - public CreateTokenRoute(MainAppDatabase database, VaultService vaultService, ILogger<CreateTokenRoute> logger) { + public CreateTokenRoute(MainAppDatabase database, ILogger<CreateTokenRoute> logger) + { _database = database; - _configuration = vaultService.GetCurrentAppConfiguration(); _logger = logger; } @@ -30,19 +29,23 @@ public class CreateTokenRoute : RouteBaseSync.WithRequest<CreateTokenRoute.Paylo /// <returns></returns> [ApiVersion(ApiSpecV1.VERSION_STRING)] [HttpPost("~/v{version:apiVersion}/api-tokens/create")] - public override ActionResult Handle(Payload request) { + public override ActionResult Handle(Payload request) + { var user = _database.Users.SingleOrDefault(c => c.Id == LoggedInUser.Id); - if (user == default) { + if (user == default) + { return NotFound(new KnownProblemModel("User does not exist")); } - var token_entropy = _configuration.APP_AES_KEY; - if (token_entropy.IsNullOrWhiteSpace()) { + var tokenEntropy = Program.AppConfiguration.APP_AES_KEY; + if (tokenEntropy.IsNullOrWhiteSpace()) + { _logger.LogWarning("No token entropy is available, Basic auth is disabled"); return NotFound(); } - var accessToken = new ApiAccessToken() { + var accessToken = new ApiAccessToken() + { User = user, ExpiryDate = request.ExpiryDate.ToUniversalTime(), AllowCreate = request.AllowCreate, @@ -53,6 +56,6 @@ public class CreateTokenRoute : RouteBaseSync.WithRequest<CreateTokenRoute.Paylo _database.AccessTokens.Add(accessToken); _database.SaveChanges(); - return Ok(Convert.ToBase64String(Encoding.UTF8.GetBytes(accessToken.Id.ToString().EncryptWithAes(token_entropy)))); + return Ok(Convert.ToBase64String(Encoding.UTF8.GetBytes(accessToken.Id.ToString().EncryptWithAes(tokenEntropy)))); } }
\ No newline at end of file |
