Test: Google oauth

This commit is contained in:
Kamigen
2024-04-15 19:10:32 -04:00
parent b6e65b416d
commit bd2410a98e
12 changed files with 132 additions and 15 deletions

View File

@@ -9,6 +9,7 @@
<PackageReference Include="Ardalis.GuardClauses" />
<PackageReference Include="AutoMapper" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" />
<PackageReference Include="Google.Apis.Oauth2.v2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" />
</ItemGroup>

View File

@@ -0,0 +1,8 @@
using Google.Apis.Oauth2.v2.Data;
namespace Hutopy.Application.Common.Interfaces;
public interface IGoogleService
{
Task<Userinfo?> GetUserInfoAsync(string accessToken);
}

View File

@@ -1,4 +1,5 @@
using Hutopy.Application.Common.Models;
using Google.Apis.Oauth2.v2.Data;
using Hutopy.Application.Common.Models;
namespace Hutopy.Application.Common.Interfaces;
@@ -11,6 +12,8 @@ public interface IIdentityService
Task<bool> AuthorizeAsync(string userId, string policyName);
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,20 @@
using Hutopy.Application.Common.Interfaces;
namespace Hutopy.Application.Google.Commands;
public record CreateGoogleUserCommand : IRequest<Guid>
{
public required string AccessToken { get; init; }
}
public class CreateGoogleUser(
IApplicationDbContext context
) : IRequestHandler<CreateGoogleUserCommand, Guid>
{
public async Task<Guid> Handle(CreateGoogleUserCommand request, CancellationToken cancellationToken)
{
await context.SaveChangesAsync(cancellationToken);
return Guid.NewGuid();
}
}