This commit is contained in:
lumijiez
2025-06-09 00:45:42 +03:00
parent ab9b80b74f
commit a695e1cce6
19 changed files with 464 additions and 173 deletions

View File

@@ -1,23 +1,33 @@
using System.Security.Claims;
using Imprink.Application.Users;
using Imprink.Domain.Common.Models;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Imprink.WebApi.Controllers.Users;
[ApiController]
[Route("/api/[controller]")]
public class UserController : ControllerBase
[Route("/users")]
public class UserController(IMediator mediator) : ControllerBase
{
[Authorize]
[HttpPost]
public IActionResult SyncUser()
[HttpPost("sync")]
public async Task<IActionResult> Sync()
{
var claims = User.Claims;
foreach (var claim in claims)
var enumerable = User.Claims as Claim[] ?? User.Claims.ToArray();
var auth0User = new Auth0User
{
Console.WriteLine($"Claim Type: {claim.Type}, Claim Value: {claim.Value}");
}
Sub = enumerable.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value ?? string.Empty,
Name = enumerable.FirstOrDefault(c => c.Type == "name")?.Value ?? string.Empty,
Nickname = enumerable.FirstOrDefault(c => c.Type == "nickname")?.Value ?? string.Empty,
Email = enumerable.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value ?? string.Empty,
EmailVerified = bool.TryParse(enumerable.FirstOrDefault(c => c.Type == "email_verified")?.Value, out var emailVerified) && emailVerified
};
await mediator.Send(new SyncUserCommand(auth0User));
return Ok("Claims logged to console.");
return Ok("User Synced.");
}
}