File size: 664 Bytes
01be06d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ecb51fa
01be06d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System.Security.Claims;

namespace TaskTrackingSystem.WebApi.Infrastructure;

public static class ClaimsPrincipalExtensions
{
    public static long GetUserId(this ClaimsPrincipal user)
    {
        var value = user.FindFirstValue(ClaimTypes.NameIdentifier);
        return long.TryParse(value, out var id) ? id : 0;
    }

    public static long GetRoleId(this ClaimsPrincipal user)
    {
        var value = user.FindFirstValue("role_id");
        return long.TryParse(value, out var id) ? id : 0;
    }

    public static string GetRoleName(this ClaimsPrincipal user)
    {
        return user.FindFirstValue(ClaimTypes.Role) ?? string.Empty;
    }



}