- Refactoring der Erweiterungsmethoden, sodass sie auf `ClaimsPrincipal` anstatt auf `ControllerBase` basieren. - Alle Verweise und Verwendungen dieser Erweiterungsmethoden im gesamten Code aktualisiert. - Dies verbessert die Flexibilität und entkoppelt das Abrufen von Benutzeransprüchen von den Controllern.
24 lines
899 B
C#
24 lines
899 B
C#
using Microsoft.AspNetCore.Mvc;
|
|
using System.Security.Claims;
|
|
|
|
namespace EnvelopeGenerator.GeneratorAPI.Controllers
|
|
{
|
|
public static class ControllerExtensions
|
|
{
|
|
public static int? GetId(this ClaimsPrincipal user)
|
|
=> int.TryParse(user.FindFirst(ClaimTypes.NameIdentifier)?.Value, out int result)
|
|
? result : null;
|
|
|
|
public static string? GetUsername(this ClaimsPrincipal user)
|
|
=> user.FindFirst(ClaimTypes.Name)?.Value;
|
|
|
|
public static string? GetName(this ClaimsPrincipal user)
|
|
=> user.FindFirst(ClaimTypes.Surname)?.Value;
|
|
|
|
public static string? GetPrename(this ClaimsPrincipal user)
|
|
=> user.FindFirst(ClaimTypes.GivenName)?.Value;
|
|
|
|
public static string? GetEmail(this ClaimsPrincipal user)
|
|
=> user.FindFirst(ClaimTypes.Email)?.Value;
|
|
}
|
|
} |