Skip to content

Commit

Permalink
Add GetPicture claims ext method
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 18, 2023
1 parent 1bf5815 commit 1abe049
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ServiceStack/src/ServiceStack.Client/ClaimUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace ServiceStack;
public static class ClaimUtils
{
public static string Admin { get; set; } = nameof(Admin);
public static string PermissionType { get; set; } = "perm";
public static string PermissionType { get; set; } = JwtClaimTypes.Permission;
public static string Picture { get; set; } = JwtClaimTypes.Picture;

public static bool IsAuthenticated(this ClaimsPrincipal? principal) => principal?.Identity?.IsAuthenticated == true;
public static ClaimsPrincipal? AuthenticatedUser(this ClaimsPrincipal? principal) =>
Expand Down Expand Up @@ -39,5 +40,9 @@ public static bool HasClaim(this ClaimsPrincipal? principal, string type, string
return true;
}
return false;
}
}

public static string? GetPicture(this ClaimsPrincipal? principal) =>
X.Map(principal?.FindFirst(Picture)?.Value, x => string.IsNullOrWhiteSpace(x) ? null : x)
?? JwtClaimTypes.DefaultProfileUrl;
}

0 comments on commit 1abe049

Please sign in to comment.