Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add IPrincipalExtensions #161

Closed
BryanWilhite opened this issue Jan 24, 2024 · 0 comments
Closed

add IPrincipalExtensions #161

BryanWilhite opened this issue Jan 24, 2024 · 0 comments
Assignees

Comments

@BryanWilhite
Copy link
Owner

/// <summary>
/// Extensions of <see cref="IPrincipal"/>
/// </summary>
public static class IPrincipalExtensions
{
    /// <summary>
    /// Converts <see cref="IPrincipal"/> to a <see cref="string"/> representation of the user’s name.
    /// </summary>
    /// <param name="principal">The principal.</param>
    /// <param name="defaultUserName">Default name of the user.</param>
    /// <returns></returns>
    public static string ToUserName(this IPrincipal? principal, string defaultUserName)
    {
        var userName = principal?.Identity?.Name;

        return userName ?? defaultUserName;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

1 participant