Class ClaimsIdentityExtensions
Inheritance
Namespace: Umbraco.Extensions
Assembly: Umbraco.Core.dll
Syntax
public static class ClaimsIdentityExtensions
Properties
View SourceRequiredBackOfficeClaimTypes
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 SourceAddOrUpdateClaim(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 |
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 |
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 |
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[] |
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 |
GetEmail(IIdentity)
Declaration
public static string? GetEmail(this IIdentity identity)
Parameters
| Type | Name | Description |
|---|---|---|
| IIdentity | identity |
Returns
| Type | Description |
|---|---|
| string |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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. |
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 |
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 |
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 |