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

@@ -17,7 +17,7 @@ public class SecretKeyGrpcAuthenticationHandler : AuthenticationHandler<Authenti
private readonly AuthService.AuthServiceClient _authClient;
private readonly IHttpContextAccessor _accessor;
public SecretKeyGrpcAuthenticationHandler(IHttpContextAccessor accessor, AuthService.AuthServiceClient authClient,
public SecretKeyGrpcAuthenticationHandler(IHttpContextAccessor accessor, AuthService.AuthServiceClient authClient,
IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
{
this._authClient = authClient;
@@ -26,20 +26,21 @@ public class SecretKeyGrpcAuthenticationHandler : AuthenticationHandler<Authenti
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
if(!Request.Headers.TryGetValue("Authorization", out var authHeader))
if (!Request.Headers.TryGetValue("Authorization", out var authHeader))
{
authHeader = string.Empty;
}
var ip = _accessor.GetIpAddress();
var authResult = await _authClient.AuthorizeAsync(new AuthRequest() {Ip = ip, SecretKey = authHeader}).ConfigureAwait(false);
var authResult = await _authClient.AuthorizeAsync(new AuthRequest() { Ip = ip, SecretKey = authHeader }).ConfigureAwait(false);
if (!authResult.Success)
{
return AuthenticateResult.Fail("Failed Authorization");
}
string uid = authResult.Uid;
var uid = authResult.Uid;
var claims = new List<Claim>
{