backend complete
This commit is contained in:
@@ -1,6 +1,43 @@
|
||||
namespace AobaServer.Services;
|
||||
using Aoba.RPC.Auth;
|
||||
|
||||
public class AobaAuthService() : Aoba.RPC.Auth.AuthRpc.AuthRpcBase
|
||||
using AobaCore;
|
||||
using AobaCore.Models;
|
||||
|
||||
using AobaServer.Models;
|
||||
using AobaServer.Utils;
|
||||
|
||||
using Grpc.Core;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
|
||||
namespace AobaServer.Services;
|
||||
|
||||
public class AobaAuthService(AccountsService accountsService, AuthInfo authInfo) : Aoba.RPC.Auth.AuthRpc.AuthRpcBase
|
||||
{
|
||||
[AllowAnonymous]
|
||||
public override async Task<LoginResponse> Login(Credentials request, ServerCallContext context)
|
||||
{
|
||||
var user = await accountsService.VerifyLoginAsync(request.User, request.Password, context.CancellationToken);
|
||||
if (user == null)
|
||||
return new LoginResponse
|
||||
{
|
||||
Error = new LoginError
|
||||
{
|
||||
Message = "Invalid login credentials"
|
||||
}
|
||||
};
|
||||
var token = user.GetToken(authInfo);
|
||||
return new LoginResponse
|
||||
{
|
||||
Jwt = new Jwt
|
||||
{
|
||||
Token = token
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user