Fixes 401 Unauthorized API responses being incorrectly cached

This commit is contained in:
BinaryAlley committed 2024-12-25 18:34:49 +02:00
1 parent f246f0bf75
commit d6af519e17
37 files changed
+298 -174

No files matched your search

@@ -62,7 +62,7 @@ public class AdminController : Controller
/// </summary>
/// <param name="roleId">The Id of the role for which to get the list of permissions.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-permissions-by-role-id/{roleId}")]
[HttpGet("api-get-permissions-by-role-id/{roleId}")]
public async Task<IActionResult> GetPermissionsByRoleId(Guid roleId, CancellationToken cancellationToken)
{
RolePermissionsModel response = await _apiHttpClient.GetAsync<RolePermissionsModel>($"roles/{roleId}/permissions", cancellationToken).ConfigureAwait(false);
@@ -74,7 +74,7 @@ public class AdminController : Controller
/// </summary>
/// <param name="userId">The Id of the user for whom to get the list of permissions.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-permissions-by-user-id/{userId}")]
[HttpGet("api-get-permissions-by-user-id/{userId}")]
public async Task<IActionResult> GetPermissionsByUserId(Guid userId, CancellationToken cancellationToken)
{
PermissionModel[] response = await _apiHttpClient.GetAsync<PermissionModel[]>($"auth/users/{userId}/permissions", cancellationToken).ConfigureAwait(false);
@@ -86,7 +86,7 @@ public class AdminController : Controller
/// </summary>
/// <param name="userId">The Id of the user for whom to get the role.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-role-by-user-id/{userId}")]
[HttpGet("api-get-role-by-user-id/{userId}")]
public async Task<IActionResult> GetRoleByUserId(Guid userId, CancellationToken cancellationToken)
{
RoleModel? response = await _apiHttpClient.GetAsync<RoleModel?>($"auth/users/{userId}/role", cancellationToken).ConfigureAwait(false);
@@ -97,7 +97,7 @@ public class AdminController : Controller
/// Gets the collection of authorization roles.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-roles")]
[HttpGet("api-get-roles")]
public async Task<IActionResult> GetRoles(CancellationToken cancellationToken)
{
RoleModel[] response = await _apiHttpClient.GetAsync<RoleModel[]>($"roles/", cancellationToken).ConfigureAwait(false);
@@ -109,7 +109,7 @@ public class AdminController : Controller
/// </summary>
/// <param name="model">The model containing the data of the role to be created.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpPost("create-role")]
[HttpPost("api-create-role")]
public async Task<IActionResult> CreateRole([FromBody] AddRoleRequestModel model, CancellationToken cancellationToken)
{
RolePermissionsModel response = await _apiHttpClient.PostAsync<RolePermissionsModel, AddRoleRequestModel>($"roles/", model, cancellationToken).ConfigureAwait(false);
@@ -121,7 +121,7 @@ public class AdminController : Controller
/// </summary>
/// <param name="model">The model containing the data of the role to be updated.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpPut("update-role")]
[HttpPut("api-update-role")]
public async Task<IActionResult> UpdateRole([FromBody] UpdateRoleRequestModel model, CancellationToken cancellationToken)
{
RolePermissionsModel response = await _apiHttpClient.PutAsync<RolePermissionsModel, UpdateRoleRequestModel>($"roles/", model, cancellationToken).ConfigureAwait(false);
@@ -133,7 +133,7 @@ public class AdminController : Controller
/// </summary>
/// <param name="roleId">The Id of the role to be deleted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpDelete("delete-role/{roleId}")]
[HttpDelete("api-delete-role/{roleId}")]
public async Task<IActionResult> DeleteRole(Guid roleId, CancellationToken cancellationToken)
{
await _apiHttpClient.DeleteAsync($"roles/{roleId}", cancellationToken).ConfigureAwait(false);
@@ -145,7 +145,7 @@ public class AdminController : Controller
/// </summary>
/// <param name="model">The model containing the data of the role to be updated.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpPut("update-user-authorization")]
[HttpPut("api-update-user-authorization")]
public async Task<IActionResult> UpdateUserAuthorization([FromBody] UpdateUserRoleAndPermissionsRequestModel model, CancellationToken cancellationToken)
{
GetAuthorizationResponse response = await _apiHttpClient.PutAsync<GetAuthorizationResponse, UpdateUserRoleAndPermissionsRequestModel>($"auth/users/{model.UserId}/role-and-permissions", model, cancellationToken).ConfigureAwait(false);
@@ -35,7 +35,7 @@ public class DirectoriesController : Controller
/// <param name="path">The path for which to get the directories.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-directories")]
[HttpGet("api-get-directories")]
public async Task<IActionResult> GetDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
IEnumerable<DirectoryModel> response = await _apiHttpClient.GetAsync<DirectoryModel[]>(
@@ -49,9 +49,10 @@ public class DirectoriesController : Controller
/// <param name="path">The path for which to get the directories.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-tree-directories")]
[HttpGet("api-get-tree-directories")]
public async Task<IActionResult> GetTreeDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
// TODO: check if it's really used
IEnumerable<FileSystemTreeNodeModel> response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>(
$"directories/get-tree-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken).ConfigureAwait(false);
return Json(new { success = true, data = response });
@@ -63,9 +64,10 @@ public class DirectoriesController : Controller
/// <param name="path">The path for which to get the directory tree.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-directory-tree")]
[HttpGet("api-get-directory-tree")]
public async Task<IActionResult> GetDirectoryTree([FromQuery] string path, [FromQuery] bool includeFiles, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
// TODO: check if it's really used
FileSystemTreeNodeModel[] response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>(
$"directories/get-directory-tree?path={Uri.EscapeDataString(path)}&includeFiles={includeFiles}&includeHiddenElements={includeHiddenElements}", cancellationToken).ConfigureAwait(false);
return Json(new { success = true, data = response });
@@ -31,7 +31,7 @@ public class DrivesController : Controller
/// Controller action for getting the list of all file system drives.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-drives")]
[HttpGet("api-get-drives")]
public async Task<IActionResult> GetDrives(CancellationToken cancellationToken)
{
FileSystemTreeNodeModel[] response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>($"drives/get-drives", cancellationToken).ConfigureAwait(false);
@@ -31,7 +31,7 @@ public class FileSystemController : Controller
/// Gets the type of the file system.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-type")]
[HttpGet("api-get-type")]
public async Task<IActionResult> GetType(CancellationToken cancellationToken)
{
FileSystemTypeModel response = await _apiHttpClient.GetAsync<FileSystemTypeModel>($"file-system/get-type", cancellationToken).ConfigureAwait(false);
@@ -35,7 +35,7 @@ public class FilesController : Controller
/// <param name="path">The path for which to get the files.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-tree-files")]
[HttpGet("api-get-tree-files")]
public async Task<IActionResult> GetTreeFiles([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
IEnumerable<FileSystemTreeNodeModel> response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>(
@@ -49,9 +49,10 @@ public class FilesController : Controller
/// <param name="path">The path for which to get the files.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-files")]
[HttpGet("api-get-files")]
public async Task<IActionResult> GetFiles([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
// TODO: check if it's really used
IEnumerable<FileModel> response = await _apiHttpClient.GetAsync<FileModel[]>(
$"files/get-files?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken).ConfigureAwait(false);
return Json(new { success = true, data = response });
@@ -33,9 +33,10 @@ public class PathController : Controller
/// </summary>
/// <param name="path">The path for which to get the root.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-path-root")]
[HttpGet("api-get-path-root")]
public async Task<IActionResult> GetPathRoot([FromQuery] string path, CancellationToken cancellationToken)
{
// TODO: check if it's really used
PathSegmentModel response = await _apiHttpClient.GetAsync<PathSegmentModel>($"path/get-path-root?path={Uri.EscapeDataString(path)}", cancellationToken).ConfigureAwait(false);
return Json(new { success = true, data = new { root = response } });
}
@@ -44,7 +45,7 @@ public class PathController : Controller
/// Gets the path separator character of the file system.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-path-separator")]
[HttpGet("api-get-path-separator")]
public async Task<IActionResult> GetPathSeparator(CancellationToken cancellationToken)
{
PathSeparatorModel response = await _apiHttpClient.GetAsync<PathSeparatorModel>($"path/get-path-separator", cancellationToken).ConfigureAwait(false);
@@ -56,7 +57,7 @@ public class PathController : Controller
/// </summary>
/// <param name="path">The path for which to get the parent path.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-path-parent")]
[HttpGet("api-get-path-parent")]
public async Task<IActionResult> GetPathParent([FromQuery] string path, CancellationToken cancellationToken)
{
PathSegmentModel[] response = await _apiHttpClient.GetAsync<PathSegmentModel[]>($"path/get-path-parent?path={Uri.EscapeDataString(path)}", cancellationToken).ConfigureAwait(false);
@@ -68,7 +69,7 @@ public class PathController : Controller
/// </summary>
/// <param name="path">The path for which to get the path segments.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("split")]
[HttpGet("api-split")]
public async Task<IActionResult> SplitPath([FromQuery] string path, CancellationToken cancellationToken)
{
PathSegmentModel[] response = await _apiHttpClient.GetAsync<PathSegmentModel[]>($"path/split?path={Uri.EscapeDataString(path)}", cancellationToken).ConfigureAwait(false);
@@ -80,7 +81,7 @@ public class PathController : Controller
/// </summary>
/// <param name="path">The path to be validated.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("validate")]
[HttpGet("api-validate")]
public async Task<IActionResult> ValidatePath([FromQuery] string path, CancellationToken cancellationToken)
{
PathValidModel response = await _apiHttpClient.GetAsync<PathValidModel>($"path/validate?path={Uri.EscapeDataString(path)}", cancellationToken).ConfigureAwait(false);
@@ -93,7 +94,7 @@ public class PathController : Controller
/// <param name="path">The path to be checked.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("check-path-exists")]
[HttpGet("api-check-path-exists")]
public async Task<IActionResult> CheckPathExists([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
PathExistsModel response = await _apiHttpClient.GetAsync<PathExistsModel>(
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.Attributes;
using Lumina.Presentation.Web.Common.Enums.Authorization;
using Lumina.Presentation.Web.Common.Models.Libraries;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -56,7 +54,7 @@ public class LibraryManagementController : Controller
/// <param name="data">The model containing the new library data.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[ValidateAntiForgeryToken]
[HttpPost("item")]
[HttpPost("api-item")]
public async Task<IActionResult> SaveLibrary([FromBody] LibraryModel data, CancellationToken cancellationToken)
{
// call different API endpoints based on whether this is a new library or an existing one
@@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using System;
using System.Collections.Generic;
@@ -132,8 +133,8 @@ public class AuthController : Controller
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[AllowAnonymous]
[ValidateAntiForgeryToken]
[HttpPost("register")]
public async Task<IActionResult> Register([FromBody] RegisterRequestModel data, CancellationToken cancellationToken)
[HttpPost("api-register")]
public async Task<IActionResult> RegisterPost([FromBody] RegisterRequestModel data, CancellationToken cancellationToken)
{
// call different endpoints based on the view hidden field - registration for normal users, or initial application admin account setup
string endpoint = data.RegistrationType == "Admin" ? "initialization" : "auth/register";
@@ -149,8 +150,8 @@ public class AuthController : Controller
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[AllowAnonymous]
[ValidateAntiForgeryToken]
[HttpPost("login")]
public async Task<IActionResult> Login([FromBody] LoginRequestModel data, CancellationToken cancellationToken)
[HttpPost("api-login")]
public async Task<IActionResult> LoginPost([FromBody] LoginRequestModel data, CancellationToken cancellationToken)
{
try
{
@@ -236,8 +237,8 @@ public class AuthController : Controller
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[AllowAnonymous]
[ValidateAntiForgeryToken]
[HttpPost("recover-password")]
public async Task<IActionResult> RecoverPassword([FromBody] RecoverPasswordRequestModel data, CancellationToken cancellationToken)
[HttpPost("api-recover-password")]
public async Task<IActionResult> RecoverPasswordPost([FromBody] RecoverPasswordRequestModel data, CancellationToken cancellationToken)
{
RecoverPasswordResponseModel response = await _apiHttpClient.PostAsync<RecoverPasswordResponseModel, RecoverPasswordRequestModel>("auth/recover-password", data, cancellationToken).ConfigureAwait(false);
return Json(new { success = true, data = response });
@@ -249,8 +250,8 @@ public class AuthController : Controller
/// <param name="data">User credentials used for password change.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[ValidateAntiForgeryToken]
[HttpPost("change-password")]
public async Task<IActionResult> ChangePassword([FromBody] ChangePasswordRequestModel data, CancellationToken cancellationToken)
[HttpPost("api-change-password")]
public async Task<IActionResult> ChangePasswordPost([FromBody] ChangePasswordRequestModel data, CancellationToken cancellationToken)
{
data = data with { Username = User?.Identity?.Name }; // assign the currently logged in user as the user for which to change the password
ChangePasswordResponseModel response = await _apiHttpClient.PostAsync<ChangePasswordResponseModel, ChangePasswordRequestModel>("auth/change-password", data, cancellationToken).ConfigureAwait(false);