Last active
April 22, 2023 18:53
-
-
Save thivi/31fb01052259cf5eae24fc62f4b6f929 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace asp.net_core_boilerplte.Utils | |
{ | |
public static class UserUtils | |
{ | |
public static string GetDisplayName(System.Security.Claims.ClaimsPrincipal user) | |
{ | |
try | |
{ | |
return user?.Claims?.Where(claim => | |
claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname" || | |
claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname" || | |
claim.Type == "username" | |
)?.First()?.Value ?? ""; | |
} | |
catch (Exception) | |
{ | |
return ""; | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment