Adjust Auth on server (#15)

* add auth that verifies identity is marked online

* few changes for testing

* handle identity with requirements

* remove unnecessary logging from auth handler

* change to UserRequirements

* fixes to checks

* fixes to UserRequirementHandler

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
rootdarkarchon
2022-10-10 19:44:30 +02:00
committed by GitHub
parent 0d8a401f13
commit d37c1208fe
11 changed files with 163 additions and 70 deletions

View File

@@ -9,19 +9,16 @@ using Google.Protobuf;
using Grpc.Core;
using MareSynchronos.API;
using MareSynchronosServer.Utils;
using MareSynchronosShared.Authentication;
using MareSynchronosShared.Models;
using MareSynchronosShared.Protos;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace MareSynchronosServer.Hubs;
public partial class MareHub
{
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
[Authorize(Policy = "Identified")]
public async Task FilesAbortUpload()
{
_logger.LogCallInfo();
@@ -31,7 +28,7 @@ public partial class MareHub
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
}
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
[Authorize(Policy = "Identified")]
public async Task FilesDeleteAll()
{
_logger.LogCallInfo();
@@ -46,7 +43,7 @@ public partial class MareHub
_ = await _fileServiceClient.DeleteFilesAsync(request, headers).ConfigureAwait(false);
}
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
[Authorize(Policy = "Identified")]
public async Task<List<DownloadFileDto>> FilesGetSizes(List<string> hashes)
{
_logger.LogCallInfo(MareHubLogger.Args(hashes.Count.ToString()));
@@ -83,7 +80,7 @@ public partial class MareHub
return response;
}
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
[Authorize(Policy = "Identified")]
public async Task<bool> FilesIsUploadFinished()
{
_logger.LogCallInfo();
@@ -92,7 +89,7 @@ public partial class MareHub
.AnyAsync(f => f.Uploader.UID == userUid && !f.Uploaded).ConfigureAwait(false);
}
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
[Authorize(Policy = "Identified")]
public async Task<List<UploadFileDto>> FilesSend(List<string> fileListHashes)
{
var userSentHashes = new HashSet<string>(fileListHashes.Distinct(StringComparer.Ordinal), StringComparer.Ordinal);
@@ -142,7 +139,7 @@ public partial class MareHub
return notCoveredFiles.Values.ToList();
}
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
[Authorize(Policy = "Identified")]
public async Task FilesUploadStreamAsync(string hash, IAsyncEnumerable<byte[]> fileContent)
{
_logger.LogCallInfo(MareHubLogger.Args(hash));