Skip to content

Instantly share code, notes, and snippets.

@thivi
Last active April 22, 2023 18:53
Show Gist options
  • Save thivi/31fb01052259cf5eae24fc62f4b6f929 to your computer and use it in GitHub Desktop.
Save thivi/31fb01052259cf5eae24fc62f4b6f929 to your computer and use it in GitHub Desktop.
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