🔊 Logging more ip address
This commit is contained in:
@@ -1,9 +1,5 @@
|
|||||||
using DysonNetwork.Pass.Wallet;
|
|
||||||
using DysonNetwork.Shared.Cache;
|
|
||||||
using DysonNetwork.Shared.Proto;
|
using DysonNetwork.Shared.Proto;
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using NodaTime;
|
|
||||||
|
|
||||||
namespace DysonNetwork.Pass.Auth;
|
namespace DysonNetwork.Pass.Auth;
|
||||||
|
|
||||||
@@ -18,7 +14,7 @@ public class AuthServiceGrpc(
|
|||||||
ServerCallContext context
|
ServerCallContext context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var (valid, session, message) = await token.AuthenticateTokenAsync(request.Token);
|
var (valid, session, message) = await token.AuthenticateTokenAsync(request.Token, request.IpAddress);
|
||||||
if (!valid || session is null)
|
if (!valid || session is null)
|
||||||
return new AuthenticateResponse { Valid = false, Message = message ?? "Authentication failed." };
|
return new AuthenticateResponse { Valid = false, Message = message ?? "Authentication failed." };
|
||||||
|
|
||||||
|
@@ -33,7 +33,10 @@ public class DysonTokenAuthHandler(
|
|||||||
AuthSession session;
|
AuthSession session;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
session = await ValidateToken(tokenInfo.Token);
|
session = await ValidateToken(
|
||||||
|
tokenInfo.Token,
|
||||||
|
Request.HttpContext.Connection.RemoteIpAddress?.ToString()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ex)
|
catch (InvalidOperationException ex)
|
||||||
{
|
{
|
||||||
@@ -78,12 +81,15 @@ public class DysonTokenAuthHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<AuthSession> ValidateToken(string token)
|
private async Task<AuthSession> ValidateToken(string token, string? ipAddress)
|
||||||
{
|
{
|
||||||
var resp = await auth.AuthenticateAsync(new AuthenticateRequest { Token = token });
|
var resp = await auth.AuthenticateAsync(new AuthenticateRequest
|
||||||
|
{
|
||||||
|
Token = token,
|
||||||
|
IpAddress = ipAddress
|
||||||
|
});
|
||||||
if (!resp.Valid) throw new InvalidOperationException(resp.Message);
|
if (!resp.Valid) throw new InvalidOperationException(resp.Message);
|
||||||
if (resp.Session == null) throw new InvalidOperationException("Session not found.");
|
return resp.Session ?? throw new InvalidOperationException("Session not found.");
|
||||||
return resp.Session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] Base64UrlDecode(string base64Url)
|
private static byte[] Base64UrlDecode(string base64Url)
|
||||||
|
@@ -70,6 +70,7 @@ service AuthService {
|
|||||||
|
|
||||||
message AuthenticateRequest {
|
message AuthenticateRequest {
|
||||||
string token = 1;
|
string token = 1;
|
||||||
|
optional google.protobuf.StringValue ip_address = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AuthenticateResponse {
|
message AuthenticateResponse {
|
||||||
|
Reference in New Issue
Block a user