#oauth changed GoogleController for the jwt flow ( using a common token if we connect from our app or from google )

This commit is contained in:
Dominic Villemure
2024-06-09 23:44:37 -04:00
parent ac87aeb4c4
commit 6f76cb2084
16 changed files with 338 additions and 842 deletions

View File

@@ -10,15 +10,12 @@ public interface IIdentityService
Task<UserModel?> FindUserByIdAsync(string id);
Task<UserModel?> GetCurrentUserAsync();
Task<UserModel?> FindUserByEmailAsync(string id);
Task<string?> LoginAsync(string email, string password);
Task<UserModel?> GetUserByUserNameAsync(string userName);
Task<bool> IsInRoleAsync(string userId, string role);
Task<bool> AuthorizeAsync(string userId, string policyName);
Task<Result> AddRoleAsync(string userId, string role);
Task<IList<string>> GetCurrentUserRolesAsync();
Task<(Result Result, string UserId)> CreateUserAsync(string userName, string password);
Task<(Result Result, string UserId)> CreateUserAsync(Userinfo userInfo);
Task<Result> DeleteUserAsync(string userId);
}

View File

@@ -0,0 +1,27 @@
using Hutopy.Application.Common.Interfaces;
namespace Hutopy.Application.Users.Commands;
public record LoginCommand : IRequest<string>
{
public required string EmailAddress { get; init; }
public required string Password { get; init; }
}
public class LoginCommandHandler : IRequestHandler<LoginCommand, string>
{
private readonly IApplicationDbContext _context;
private readonly IIdentityService _identityService;
public LoginCommandHandler(IApplicationDbContext context, IIdentityService identityService)
{
_context = context;
_identityService = identityService;
}
public async Task<string> Handle(LoginCommand request, CancellationToken cancellationToken)
{
var jwt = await _identityService.LoginAsync(request.EmailAddress, request.Password);
return jwt ?? "Invalid login credentials";
}
}