Erweiterungsmethoden hinzugefügt, um Benutzeransprüche in ControllerBase für ID, Benutzernamen, Namen, Vornamen und E-Mail abzurufen.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user