Test: Google oauth
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
8
src/Application/Common/Interfaces/IGoogleService.cs
Normal file
8
src/Application/Common/Interfaces/IGoogleService.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Google.Apis.Oauth2.v2.Data;
|
||||
|
||||
namespace Hutopy.Application.Common.Interfaces;
|
||||
|
||||
public interface IGoogleService
|
||||
{
|
||||
Task<Userinfo?> GetUserInfoAsync(string accessToken);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
20
src/Application/Google/Commands/CreateGoogleUser.cs
Normal file
20
src/Application/Google/Commands/CreateGoogleUser.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user