Ajoute une page utilisateur et une persistance MySQL

This commit is contained in:
2026-04-14 20:03:26 +02:00
parent d0f9c76b26
commit 5cf46dce31
14 changed files with 1106 additions and 3 deletions

View File

@@ -0,0 +1,40 @@
using System.Security.Claims;
namespace ChessCubing.Server.Users;
public sealed record AuthenticatedSiteUser(
string Subject,
string Username,
string? Email,
string DisplayName);
public static class AuthenticatedSiteUserFactory
{
public static AuthenticatedSiteUser? FromClaimsPrincipal(ClaimsPrincipal user)
{
if (user.Identity?.IsAuthenticated != true)
{
return null;
}
var subject = user.FindFirst("sub")?.Value
?? user.FindFirst(ClaimTypes.NameIdentifier)?.Value;
if (string.IsNullOrWhiteSpace(subject))
{
return null;
}
var username = user.FindFirst("preferred_username")?.Value
?? user.Identity?.Name
?? subject;
var email = user.FindFirst("email")?.Value;
var displayName = user.FindFirst("name")?.Value
?? username;
return new AuthenticatedSiteUser(
subject.Trim(),
username.Trim(),
string.IsNullOrWhiteSpace(email) ? null : email.Trim(),
displayName.Trim());
}
}