40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
using DysonNetwork.Pass.Wallet;
|
|
using DysonNetwork.Shared.Cache;
|
|
using DysonNetwork.Shared.Proto;
|
|
using Grpc.Core;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NodaTime;
|
|
|
|
namespace DysonNetwork.Pass.Auth;
|
|
|
|
public class AuthServiceGrpc(
|
|
TokenAuthService token,
|
|
AuthService auth
|
|
)
|
|
: Shared.Proto.AuthService.AuthServiceBase
|
|
{
|
|
public override async Task<AuthenticateResponse> Authenticate(
|
|
AuthenticateRequest request,
|
|
ServerCallContext context
|
|
)
|
|
{
|
|
var (valid, session, message) = await token.AuthenticateTokenAsync(request.Token);
|
|
if (!valid || session is null)
|
|
return new AuthenticateResponse { Valid = false, Message = message ?? "Authentication failed." };
|
|
|
|
return new AuthenticateResponse { Valid = true, Session = session.ToProtoValue() };
|
|
}
|
|
|
|
public override async Task<ValidateResponse> ValidatePin(ValidatePinRequest request, ServerCallContext context)
|
|
{
|
|
var accountId = Guid.Parse(request.AccountId);
|
|
var valid = await auth.ValidatePinCode(accountId, request.Pin);
|
|
return new ValidateResponse { Valid = valid };
|
|
}
|
|
|
|
public override async Task<ValidateResponse> ValidateCaptcha(ValidateCaptchaRequest request, ServerCallContext context)
|
|
{
|
|
var valid = await auth.ValidateCaptcha(request.Token);
|
|
return new ValidateResponse { Valid = valid };
|
|
}
|
|
} |