Search Results for

    Show / Hide Table of Contents
    View Source

    Class ClaimsIdentityExtensions

    Inheritance
    object
    Namespace: Umbraco.Extensions
    Assembly: Umbraco.Core.dll
    Syntax
    public static class ClaimsIdentityExtensions

    Properties

    View Source

    RequiredBackOfficeClaimTypes

    Returns the required claim types for a back office identity

    Declaration
    public static IEnumerable<string> RequiredBackOfficeClaimTypes { get; }
    Property Value
    Type Description
    IEnumerable<string>
    Remarks

    This does not include the role claim type or allowed apps type since that is a collection and in theory could be empty

    Methods

    View Source

    AddOrUpdateClaim(ClaimsIdentity, Claim?)

    Adds or updates and existing claim.

    Declaration
    public static void AddOrUpdateClaim(this ClaimsIdentity identity, Claim? claim)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    Claim claim
    View Source

    AddRequiredClaims(ClaimsIdentity, string, Guid, string, string, IEnumerable<int>?, IEnumerable<int>?, string, string, IEnumerable<string>, IEnumerable<string>)

    Add the required claims to be a BackOffice ClaimsIdentity

    Declaration
    public static void AddRequiredClaims(this ClaimsIdentity identity, string userId, Guid userKey, string username, string realName, IEnumerable<int>? startContentNodes, IEnumerable<int>? startMediaNodes, string culture, string securityStamp, IEnumerable<string> allowedApps, IEnumerable<string> roles)
    Parameters
    Type Name Description
    ClaimsIdentity identity

    this

    string userId

    The users Id

    Guid userKey

    The users key

    string username

    Username

    string realName

    Real name

    IEnumerable<int> startContentNodes

    Start content nodes

    IEnumerable<int> startMediaNodes

    Start media nodes

    string culture

    The locality of the user

    string securityStamp

    Security stamp

    IEnumerable<string> allowedApps

    Allowed apps

    IEnumerable<string> roles

    Roles

    View Source

    FindFirstValue(ClaimsIdentity, string)

    Returns the first claim value found in the System.Security.Claims.ClaimsIdentity for the given claimType

    Declaration
    public static string? FindFirstValue(this ClaimsIdentity identity, string claimType)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    string claimType
    Returns
    Type Description
    string

    The string value of the claim if found otherwise null

    View Source

    GetAllowedApplications(ClaimsIdentity)

    Get the allowed applications from a ClaimsIdentity

    Declaration
    [Obsolete("Please use IUser.AllowedSections instead. Will be removed in V15.")]
    public static string[] GetAllowedApplications(this ClaimsIdentity identity)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    Returns
    Type Description
    string[]
    View Source

    GetCultureString(ClaimsIdentity)

    Get the culture string from a ClaimsIdentity

    Declaration
    public static string? GetCultureString(this ClaimsIdentity identity)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    Returns
    Type Description
    string

    Culture string

    View Source

    GetEmail(IIdentity)

    Declaration
    public static string? GetEmail(this IIdentity identity)
    Parameters
    Type Name Description
    IIdentity identity
    Returns
    Type Description
    string
    View Source

    GetId(ClaimsIdentity)

    Get the user ID from a ClaimsIdentity

    Declaration
    public static int? GetId(this ClaimsIdentity identity)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    Returns
    Type Description
    int?

    User ID as integer

    View Source

    GetRealName(ClaimsIdentity)

    Get the real name belonging to the user from a ClaimsIdentity

    Declaration
    public static string? GetRealName(this ClaimsIdentity identity)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    Returns
    Type Description
    string

    Real name of the user

    View Source

    GetRoles(ClaimsIdentity)

    Get the roles assigned to a user from a ClaimsIdentity

    Declaration
    public static string[] GetRoles(this ClaimsIdentity identity)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    Returns
    Type Description
    string[]

    Array of roles

    View Source

    GetSecurityStamp(ClaimsIdentity)

    Get the security stamp from a ClaimsIdentity

    Declaration
    public static string? GetSecurityStamp(this ClaimsIdentity identity)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    Returns
    Type Description
    string

    Security stamp

    View Source

    GetStartContentNodes(ClaimsIdentity)

    Get the start content nodes from a ClaimsIdentity

    Declaration
    [Obsolete("Please use the UserExtensions class to access user start node info. Will be removed in V15.")]
    public static int[] GetStartContentNodes(this ClaimsIdentity identity)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    Returns
    Type Description
    int[]

    Array of start content nodes

    View Source

    GetStartMediaNodes(ClaimsIdentity)

    Get the start media nodes from a ClaimsIdentity

    Declaration
    [Obsolete("Please use the UserExtensions class to access user start node info. Will be removed in V15.")]
    public static int[] GetStartMediaNodes(this ClaimsIdentity identity)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    Returns
    Type Description
    int[]

    Array of start media nodes

    View Source

    GetUserId(IIdentity)

    Returns the user id from the System.Security.Principal.IIdentity of either the claim type System.Security.Claims.ClaimTypes.NameIdentifier or "sub"

    Declaration
    public static string? GetUserId(this IIdentity identity)
    Parameters
    Type Name Description
    IIdentity identity
    Returns
    Type Description
    string

    The string value of the user id if found otherwise null

    View Source

    GetUserId<T>(IIdentity)

    Declaration
    public static T? GetUserId<T>(this IIdentity identity)
    Parameters
    Type Name Description
    IIdentity identity
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    View Source

    GetUserKey(IIdentity)

    Returns the user key from the System.Security.Principal.IIdentity of the claim type "sub".

    Declaration
    public static Guid? GetUserKey(this IIdentity identity)
    Parameters
    Type Name Description
    IIdentity identity
    Returns
    Type Description
    Guid?

    The string value of the user id if found otherwise null.

    View Source

    GetUserName(IIdentity)

    Returns the user name from the System.Security.Principal.IIdentity of either the claim type System.Security.Claims.ClaimTypes.Name or "preferred_username"

    Declaration
    public static string? GetUserName(this IIdentity identity)
    Parameters
    Type Name Description
    IIdentity identity
    Returns
    Type Description
    string

    The string value of the user name if found otherwise null

    View Source

    GetUsername(ClaimsIdentity)

    Get the username of the user from a ClaimsIdentity

    Declaration
    public static string? GetUsername(this ClaimsIdentity identity)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    Returns
    Type Description
    string

    Username of the user

    View Source

    VerifyBackOfficeIdentity(ClaimsIdentity, out ClaimsIdentity)

    Verify that a ClaimsIdentity has all the required claim types

    Declaration
    public static bool VerifyBackOfficeIdentity(this ClaimsIdentity identity, out ClaimsIdentity verifiedIdentity)
    Parameters
    Type Name Description
    ClaimsIdentity identity
    ClaimsIdentity verifiedIdentity

    Verified identity wrapped in a ClaimsIdentity with BackOfficeAuthentication type

    Returns
    Type Description
    bool

    True if ClaimsIdentity

    • Edit this page
    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX