yavsc/src/Yavsc.Server/Helpers/UserHelpers.cs

28 lines
732 B
C#
Raw Normal View History

2023-03-19 17:57:55 +00:00
using System.Security.Claims;
2017-02-01 19:53:10 +01:00
namespace Yavsc.Server.Helpers
2017-02-01 19:53:10 +01:00
{
public static class UserHelpers
{
2023-03-19 17:57:55 +00:00
public static string GetUserId(this ClaimsPrincipal user)
{
2024-03-04 01:02:19 +00:00
return user.FindFirstValue("sub");
2023-03-19 17:57:55 +00:00
}
2024-12-03 01:44:58 +00:00
2023-03-19 17:57:55 +00:00
public static string GetUserName(this ClaimsPrincipal user)
{
2025-07-10 15:19:28 +01:00
return user.FindFirstValue("name");
2023-03-19 17:57:55 +00:00
}
public static bool IsSignedIn(this ClaimsPrincipal user)
{
return user.Identity.IsAuthenticated;
}
2025-07-31 11:44:02 +01:00
public static bool IsInMsRole(this ClaimsPrincipal user, string roleName)
{
return user.HasClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role", roleName);
}
2017-02-01 19:53:10 +01:00
}
}