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<System.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 |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity | |
System.Security.Claims.Claim | claim |
AddRequiredClaims(ClaimsIdentity, String, String, String, Nullable<IEnumerable<Int32>>, Nullable<IEnumerable<Int32>>, 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, string username, string realName, IEnumerable<int>? startContentNodes, IEnumerable<int>? startMediaNodes, string culture, string securityStamp, IEnumerable<string> allowedApps, IEnumerable<string> roles)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity | this |
System.String | userId | The users Id |
System.String | username | Username |
System.String | realName | Real name |
System.Nullable<IEnumerable<System.Int32>> | startContentNodes | Start content nodes |
System.Nullable<IEnumerable<System.Int32>> | startMediaNodes | Start media nodes |
System.String | culture | The locality of the user |
System.String | securityStamp | Security stamp |
IEnumerable<System.String> | allowedApps | Allowed apps |
IEnumerable<System.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 |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity | |
System.String | claimType |
Returns
Type | Description |
---|---|
System.String | The string value of the claim if found otherwise null |
GetAllowedApplications(ClaimsIdentity)
Get the allowed applications from a ClaimsIdentity
Declaration
public static string[] GetAllowedApplications(this ClaimsIdentity identity)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity |
Returns
Type | Description |
---|---|
System.String[] |
GetCultureString(ClaimsIdentity)
Get the culture string from a ClaimsIdentity
Declaration
public static string GetCultureString(this ClaimsIdentity identity)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity |
Returns
Type | Description |
---|---|
System.String | Culture string |
GetEmail(IIdentity)
Declaration
public static string GetEmail(this IIdentity identity)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Principal.IIdentity | identity |
Returns
Type | Description |
---|---|
System.String |
GetId(ClaimsIdentity)
Get the user ID from a ClaimsIdentity
Declaration
public static int? GetId(this ClaimsIdentity identity)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity |
Returns
Type | Description |
---|---|
System.Nullable<System.Int32> | 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 |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity |
Returns
Type | Description |
---|---|
System.String | Security stamp |
GetStartContentNodes(ClaimsIdentity)
Get the start content nodes from a ClaimsIdentity
Declaration
public static int[] GetStartContentNodes(this ClaimsIdentity identity)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity |
Returns
Type | Description |
---|---|
System.Int32[] | Array of start content nodes |
GetStartMediaNodes(ClaimsIdentity)
Get the start media nodes from a ClaimsIdentity
Declaration
public static int[] GetStartMediaNodes(this ClaimsIdentity identity)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity |
Returns
Type | Description |
---|---|
System.Int32[] | 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 |
---|---|---|
System.Security.Principal.IIdentity | identity |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.Security.Principal.IIdentity | identity |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
GetUsername(ClaimsIdentity)
Get the username of the user from a ClaimsIdentity
Declaration
public static string GetUsername(this ClaimsIdentity identity)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity |
Returns
Type | Description |
---|---|
System.String | Username of the user |
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 |
---|---|---|
System.Security.Principal.IIdentity | identity |
Returns
Type | Description |
---|---|
System.String | The string value of the user name if found otherwise null |
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 |
---|---|---|
System.Security.Claims.ClaimsIdentity | identity | |
System.Security.Claims.ClaimsIdentity | verifiedIdentity | Verified identity wrapped in a ClaimsIdentity with BackOfficeAuthentication type |
Returns
Type | Description |
---|---|
System.Boolean | True if ClaimsIdentity |