24 lines
979 B
C#

using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
namespace EnvelopeGenerator.GeneratorAPI.Controllers
{
public static class ControllerExtensions
{
public static int? GetId(this ControllerBase controller)
=> int.TryParse(controller.User.FindFirst(ClaimTypes.NameIdentifier)?.Value, out int result)
? result : null;
public static string? GetUsername(this ControllerBase controller)
=> controller.User.FindFirst(ClaimTypes.Name)?.Value;
public static string? GetName(this ControllerBase controller)
=> controller.User.FindFirst(ClaimTypes.Surname)?.Value;
public static string? GetPrename(this ControllerBase controller)
=> controller.User.FindFirst(ClaimTypes.GivenName)?.Value;
public static string? GetEmail(this ControllerBase controller)
=> controller.User.FindFirst(ClaimTypes.Email)?.Value;
}
}