mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
fix: denies unauthenticated users on policy-protected endpoints
This commit is contained in:
1 parent
7ad7ad308e
commit
d10233f4e3
3 files changed
+20
-15
No files matched your search
@@ -62,8 +62,10 @@ public class AuthorizationService : IAuthorizationService
|
||||
/// <returns>The user's authorization details.</returns>
|
||||
private async Task<GetAuthorizationResponse> GetUserAuthorizationAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
// get the id of the currently logged in user
|
||||
string userId = _httpContextAccessor.HttpContext!.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
|
||||
return await _apiHttpClient.GetAsync<GetAuthorizationResponse>($"auth/get-authorization?userId={Uri.EscapeDataString(userId.ToString())}", cancellationToken);
|
||||
// anonymous users and users without an identifier claim have no role or permissions, so deny without querying the API
|
||||
string? userId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
return new GetAuthorizationResponse(Guid.Empty, string.Empty, []);
|
||||
return await _apiHttpClient.GetAsync<GetAuthorizationResponse>($"auth/get-authorization?userId={Uri.EscapeDataString(userId)}", cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user