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

@@ -1,3 +1,4 @@
using Google.Apis.Oauth2.v2.Data;
using Hutopy.Application.Common.Interfaces;
using Hutopy.Application.Common.Models;
using Microsoft.AspNetCore.Authorization;
@@ -30,6 +31,23 @@ public class IdentityService(
return (result.ToApplicationResult(), user.Id);
}
public async Task<(Result Result, string UserId)> CreateUserAsync(Userinfo userInfo)
{
var user = new ApplicationUser
{
UserName = userInfo.Name,
Email = userInfo.Email,
FirstName = userInfo.GivenName,
LastName = userInfo.FamilyName
};
var password = Guid.NewGuid().ToString("N")[..32];
var result = await userManager.CreateAsync(user, password);
return (result.ToApplicationResult(), user.Id);
}
public async Task<bool> IsInRoleAsync(string userId, string role)
{