🔊 Logging more ip address

This commit is contained in:
2025-08-25 23:42:41 +08:00
parent d4de5aeac2
commit 344007af66
3 changed files with 13 additions and 10 deletions

View File

@@ -1,9 +1,5 @@
using DysonNetwork.Pass.Wallet;
using DysonNetwork.Shared.Cache;
using DysonNetwork.Shared.Proto;
using Grpc.Core;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Pass.Auth;
@@ -18,7 +14,7 @@ public class AuthServiceGrpc(
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)
return new AuthenticateResponse { Valid = false, Message = message ?? "Authentication failed." };

View File

@@ -33,7 +33,10 @@ public class DysonTokenAuthHandler(
AuthSession session;
try
{
session = await ValidateToken(tokenInfo.Token);
session = await ValidateToken(
tokenInfo.Token,
Request.HttpContext.Connection.RemoteIpAddress?.ToString()
);
}
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.Session == null) throw new InvalidOperationException("Session not found.");
return resp.Session;
return resp.Session ?? throw new InvalidOperationException("Session not found.");
}
private static byte[] Base64UrlDecode(string base64Url)

View File

@@ -70,6 +70,7 @@ service AuthService {
message AuthenticateRequest {
string token = 1;
optional google.protobuf.StringValue ip_address = 2;
}
message AuthenticateResponse {