aboutsummaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-09-20 09:24:27 +0200
committerivarlovlie <git@ivarlovlie.no>2022-09-20 09:24:27 +0200
commita9072370ca1eb9a5cce928b1d487db0f307edea6 (patch)
tree59c3c23df930a8b5f888dc7813923abf4ceefed4 /server/src
parent56fa963a1d63cbe0bf28e29e717cceaa417c45c1 (diff)
downloadgreatoffice-a9072370ca1eb9a5cce928b1d487db0f307edea6.tar.xz
greatoffice-a9072370ca1eb9a5cce928b1d487db0f307edea6.zip
feat: Move old apps into it's own directory
Diffstat (limited to 'server/src')
-rw-r--r--server/src/Data/Models/LoggedInUserModel.cs1
-rw-r--r--server/src/Data/Static/AppConfiguration.cs1
-rw-r--r--server/src/Endpoints/V1/ApiTokens/CreateTokenRoute.cs86
-rw-r--r--server/src/Program.cs2
4 files changed, 46 insertions, 44 deletions
diff --git a/server/src/Data/Models/LoggedInUserModel.cs b/server/src/Data/Models/LoggedInUserModel.cs
index 4a5bef9..d802b77 100644
--- a/server/src/Data/Models/LoggedInUserModel.cs
+++ b/server/src/Data/Models/LoggedInUserModel.cs
@@ -2,7 +2,6 @@ namespace IOL.GreatOffice.Api.Data.Models;
public class LoggedInUserModel
{
- public LoggedInUserModel() { }
public Guid Id { get; set; }
public string Username { get; set; }
}
diff --git a/server/src/Data/Static/AppConfiguration.cs b/server/src/Data/Static/AppConfiguration.cs
index d05f2c2..4ee7a8e 100644
--- a/server/src/Data/Static/AppConfiguration.cs
+++ b/server/src/Data/Static/AppConfiguration.cs
@@ -1,5 +1,4 @@
using System.Security.Cryptography.X509Certificates;
-using System.Text;
namespace IOL.GreatOffice.Api.Data.Static;
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<ApiAccessToken.ApiAccessTokenDto>.WithActionResult
{
- private readonly AppDbContext _context;
- private readonly AppConfiguration _configuration;
- private readonly ILogger<CreateTokenRoute> _logger;
+ private readonly AppDbContext _context;
+ private readonly AppConfiguration _configuration;
+ private readonly ILogger<CreateTokenRoute> _logger;
- public CreateTokenRoute(AppDbContext context, VaultService vaultService, ILogger<CreateTokenRoute> logger) {
- _context = context;
- _configuration = vaultService.GetCurrentAppConfiguration();
- _logger = logger;
- }
+ public CreateTokenRoute(AppDbContext context, VaultService vaultService, ILogger<CreateTokenRoute> logger)
+ {
+ _context = context;
+ _configuration = vaultService.GetCurrentAppConfiguration();
+ _logger = logger;
+ }
- /// <summary>
- /// Create a new api token with the provided claims.
- /// </summary>
- /// <param name="request">The claims to set on the api token</param>
- /// <returns></returns>
- [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"));
- }
+ /// <summary>
+ /// Create a new api token with the provided claims.
+ /// </summary>
+ /// <param name="request">The claims to set on the api token</param>
+ /// <returns></returns>
+ [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))));
+ }
}
diff --git a/server/src/Program.cs b/server/src/Program.cs
index 1d831e3..050f504 100644
--- a/server/src/Program.cs
+++ b/server/src/Program.cs
@@ -191,7 +191,7 @@ public static class Program
app.UseCors(cors => {
cors.AllowAnyMethod();
cors.AllowAnyHeader();
- cors.WithOrigins("http://localhost:3000", "http://localhost:3002", "http://localhost:3001");
+ cors.WithOrigins("http://localhost:3000", "http://localhost:3002", "http://localhost:3001", "http://localhost:5173");
cors.AllowCredentials();
});
}