We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you add some baseControllers and extensions
public class BaseController<T> : Controller where T : Controller { private IBreadCrumbService _breadCrumbInstance; private INotyfService _toastInstance; private ILogger _loggerInstance; protected INotyfService _toast => _toastInstance ??= HttpContext.RequestServices.GetService<INotyfService>(); protected IBreadCrumbService _breadcrumbs => _breadCrumbInstance ??= HttpContext.RequestServices.GetService<IBreadCrumbService>(); protected ILogger _logger => _loggerInstance ??= HttpContext.RequestServices.GetService<ILogger<T>>(); }
Claims
using System.Security.Claims; namespace Infrastructure.Extensions; public static class ClaimsPrincipalExtensions { /// <summary> /// Returns the principal user email claim value /// </summary> /// <param name="principal"></param> /// <returns></returns> public static string GetUserEmail(this ClaimsPrincipal principal) { return principal.FindFirstValue(ClaimTypes.Email) ?? string.Empty; } /// <summary> /// Returns the principal user id identifier claim value /// </summary> /// <param name="principal"></param> /// <returns></returns> public static string GetUserId(this ClaimsPrincipal principal) { return principal.FindFirstValue(ClaimTypes.NameIdentifier) ?? string.Empty; } /// <summary> /// Returns the principal user username /// </summary> /// <param name="principal"></param> /// <returns></returns> public static string GetUsername(this ClaimsPrincipal principal) { return principal.FindFirstValue(ClaimTypes.Name) ?? string.Empty; } public static string FirstName(this ClaimsPrincipal principal) { return principal.FindFirstValue(ClaimTypes.GivenName) ?? string.Empty; } public static string LastName(this ClaimsPrincipal principal) { return principal.FindFirstValue(ClaimTypes.Surname) ?? string.Empty; } /// <summary> /// Checks to see if the user given by id matches the principal user id /// </summary> /// <param name="principal"></param> /// <param name="id"></param> /// <returns></returns> public static bool IsCurrentUser(this ClaimsPrincipal principal, string id) { var currentUserId = GetUserId(principal); return string.Equals(currentUserId, id, StringComparison.OrdinalIgnoreCase); } /// <summary> /// Returns the roles held by principal /// </summary> /// <param name="principal"></param> /// <returns></returns> public static IEnumerable<string> GetRoles(this ClaimsPrincipal principal) { return principal.Identities.SelectMany(i => { return i.Claims .Where(c => c.Type == i.RoleClaimType) .Select(c => c.Value) .ToList(); }); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Can you add some baseControllers and extensions
Claims
The text was updated successfully, but these errors were encountered: