Interface IUmbracoUserManager<TUser>
A user manager for Umbraco (either back office users or front-end members)
Namespace: Umbraco.Cms.Core.Security
Assembly: Umbraco.Infrastructure.dll
Syntax
public interface IUmbracoUserManager<TUser>
where TUser : UmbracoIdentityUser
Type Parameters
Name | Description |
---|---|
TUser | The type of user |
Methods
View SourceAccessFailedAsync(TUser)
Increments the access failed count for the user as an asynchronous operation. If the failed access account is greater than or equal to the configured maximum number of attempts, the user will be locked out for the configured lockout time span.
Declaration
Task<IdentityResult> AccessFailedAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose failed access count to increment. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The |
AddLoginAsync(TUser, UserLoginInfo)
Adds an external Microsoft.AspNetCore.Identity.UserLoginInfo to the specified user.
Declaration
Task<IdentityResult> AddLoginAsync(TUser user, UserLoginInfo login)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to add the login to. |
UserLoginInfo | login | The external Microsoft.AspNetCore.Identity.UserLoginInfo to add to the specified user. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The System.Threading.Tasks.Task that represents the asynchronous operation, containing the Microsoft.AspNetCore.Identity.IdentityResult of the operation. |
AddPasswordAsync(TUser, String)
Adds the password
to the specified user
only if the user
does not already have a password.
Declaration
Task<IdentityResult> AddPasswordAsync(TUser user, string password)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose password should be set. |
System.String | password | The password to set. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The |
AddToRolesAsync(TUser, IEnumerable<String>)
Add the specified user to the named roles
Declaration
Task<IdentityResult> AddToRolesAsync(TUser user, IEnumerable<string> roles)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to add to the named roles |
IEnumerable<System.String> | roles | The name of the roles to add the user to. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The Task that represents the asynchronous operation, containing the IdentityResult of the operation |
ChangePasswordAsync(TUser, String, String)
Changes a user's password after confirming the specified currentPassword
is correct,
as an asynchronous operation.
Declaration
Task<IdentityResult> ChangePasswordAsync(TUser user, string currentPassword, string newPassword)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose password should be set. |
System.String | currentPassword | The current password to validate before changing. |
System.String | newPassword | The new password to set for the specified |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The |
ChangePasswordWithResetAsync(String, String, String)
This is a special method that will reset the password but will raise the Password Changed event instead of the reset event
Declaration
Task<IdentityResult> ChangePasswordWithResetAsync(string userId, string token, string newPassword)
Parameters
Type | Name | Description |
---|---|---|
System.String | userId | |
System.String | token | |
System.String | newPassword |
Returns
Type | Description |
---|---|
Task<IdentityResult> |
Remarks
We use this because in the back office the only way an admin can change another user's password without first knowing their password is to generate a token and reset it, however, when we do this we want to track a password change, not a password reset
CheckPasswordAsync(TUser, String)
Returns a flag indicating whether the given password
is valid for the
specified user
.
Declaration
Task<bool> CheckPasswordAsync(TUser user, string password)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose password should be validated. |
System.String | password | The password to validate |
Returns
Type | Description |
---|---|
Task<System.Boolean> | The |
ConfirmEmailAsync(TUser, String)
Validates that an email confirmation token matches the specified user
.
Declaration
Task<IdentityResult> ConfirmEmailAsync(TUser user, string token)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to validate the token against. |
System.String | token | The email confirmation token to validate. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The |
CreateAsync(TUser)
Creates the specified user
in the backing store with no password,
as an asynchronous operation.
Declaration
Task<IdentityResult> CreateAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to create. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The |
CreateAsync(TUser, String)
Creates the specified user
in the backing store with a password,
as an asynchronous operation.
Declaration
Task<IdentityResult> CreateAsync(TUser user, string password)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to create. |
System.String | password | The password to add to the user. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The |
DeleteAsync(TUser)
Deletes a user
Declaration
Task<IdentityResult> DeleteAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user |
Returns
Type | Description |
---|---|
Task<IdentityResult> | A |
FindByEmailAsync(String)
Gets the user, if any, associated with the normalized value of the specified email address. Note: Its recommended that identityOptions.User.RequireUniqueEmail be set to true when using this method, otherwise the store may throw if there are users with duplicate emails.
Declaration
Task<TUser> FindByEmailAsync(string email)
Parameters
Type | Name | Description |
---|---|---|
System.String | The email address to return the user for. |
Returns
Type | Description |
---|---|
Task<TUser> | The task object containing the results of the asynchronous lookup operation, the user, if any, associated with a normalized value of the specified email address. |
FindByIdAsync(String)
Finds and returns a user, if any, who has the specified userId
.
Declaration
Task<TUser> FindByIdAsync(string userId)
Parameters
Type | Name | Description |
---|---|---|
System.String | userId | The user ID to search for. |
Returns
Type | Description |
---|---|
Task<TUser> | The |
FindByLoginAsync(String, String)
Finds a user by the external login provider
Declaration
Task<TUser> FindByLoginAsync(string loginProvider, string providerKey)
Parameters
Type | Name | Description |
---|---|---|
System.String | loginProvider | |
System.String | providerKey |
Returns
Type | Description |
---|---|
Task<TUser> | A |
FindByNameAsync(String)
Finds and returns a user, if any, who has the specified user name.
Declaration
Task<TUser> FindByNameAsync(string userName)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name to search for. |
Returns
Type | Description |
---|---|
Task<TUser> | The |
GenerateEmailConfirmationTokenAsync(TUser)
Generates an email confirmation token for the specified user.
Declaration
Task<string> GenerateEmailConfirmationTokenAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to generate an email confirmation token for. |
Returns
Type | Description |
---|---|
Task<System.String> | The |
GeneratePassword()
Generate a password for a user based on the current password validator
Declaration
string GeneratePassword()
Returns
Type | Description |
---|---|
System.String | A generated password |
GeneratePasswordResetTokenAsync(TUser)
Generates a password reset token for the specified user
, using
the configured password reset token provider.
Declaration
Task<string> GeneratePasswordResetTokenAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to generate a password reset token for. |
Returns
Type | Description |
---|---|
Task<System.String> | The |
GenerateTwoFactorTokenAsync(TUser, String)
Generates a two factor token for the user
Declaration
Task<string> GenerateTwoFactorTokenAsync(TUser user, string tokenProvider)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | |
System.String | tokenProvider |
Returns
Type | Description |
---|---|
Task<System.String> | A |
GetEmailAsync(TUser)
Gets the email address for the specified user.
Declaration
Task<string> GetEmailAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose email should be returned. |
Returns
Type | Description |
---|---|
Task<System.String> | The task object containing the results of the asynchronous operation, the email address for the specified user. |
GetLoginsAsync(TUser)
Gets the external logins for the user
Declaration
Task<IList<UserLoginInfo>> GetLoginsAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user |
Returns
Type | Description |
---|---|
Task<IList<UserLoginInfo>> | A |
GetPhoneNumberAsync(TUser)
Gets the telephone number, if any, for the specified user.
Declaration
Task<string> GetPhoneNumberAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose telephone number should be retrieved. |
Returns
Type | Description |
---|---|
Task<System.String> | The System.Threading.Tasks.Task that represents the asynchronous operation, containing the user's telephone number, if any. |
Remarks
A user can only support a phone number if the BackOfficeUserStore is replaced with another that implements IUserPhoneNumberStore
GetRolesAsync(TUser)
Gets a list of role names the specified user belongs to.
Declaration
Task<IList<string>> GetRolesAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose role names to retrieve. |
Returns
Type | Description |
---|---|
Task<IList<System.String>> | The Task that represents the asynchronous operation, containing a list of role names. |
GetTwoFactorEnabledAsync(TUser)
Returns a flag indicating whether the specified user
has two factor authentication enabled or
not,
as an asynchronous operation.
Declaration
Task<bool> GetTwoFactorEnabledAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose two factor authentication enabled status should be retrieved. |
Returns
Type | Description |
---|---|
Task<System.Boolean> | The |
GetUserAsync(ClaimsPrincipal)
Get the TUser
from a System.Security.Claims.ClaimsPrincipal
Declaration
Task<TUser> GetUserAsync(ClaimsPrincipal principal)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Claims.ClaimsPrincipal | principal | The System.Security.Claims.ClaimsPrincipal |
Returns
Type | Description |
---|---|
Task<TUser> | A |
GetUserId(ClaimsPrincipal)
Get the user id from the System.Security.Claims.ClaimsPrincipal
Declaration
string GetUserId(ClaimsPrincipal principal)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Claims.ClaimsPrincipal | principal | the System.Security.Claims.ClaimsPrincipal |
Returns
Type | Description |
---|---|
System.String | Returns the user id from the System.Security.Claims.ClaimsPrincipal |
GetUserIdAsync(TUser)
Gets the user id of a user
Declaration
Task<string> GetUserIdAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user |
Returns
Type | Description |
---|---|
Task<System.String> | A |
GetValidTwoFactorProvidersAsync(TUser)
Gets a list of valid two factor token providers for the specified user
,
as an asynchronous operation.
Declaration
Task<IList<string>> GetValidTwoFactorProvidersAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user the whose two factor authentication providers will be returned. |
Returns
Type | Description |
---|---|
Task<IList<System.String>> | The |
IsEmailConfirmedAsync(TUser)
Gets a flag indicating whether the email address for the specified user
has been verified, true
if the email address is verified otherwise
false.
Declaration
Task<bool> IsEmailConfirmedAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose email confirmation status should be returned. |
Returns
Type | Description |
---|---|
Task<System.Boolean> | The task object containing the results of the asynchronous operation, a flag indicating whether the email address
for the specified |
IsLockedOutAsync(TUser)
Override to check the user approval value as well as the user lock out date, by default this only checks the user's locked out date
Declaration
Task<bool> IsLockedOutAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user |
Returns
Type | Description |
---|---|
Task<System.Boolean> |
Remarks
In the ASP.NET Identity world, there is only one value for being locked out, in Umbraco we have 2 so when checking this for Umbraco we need to check both values
RemoveFromRolesAsync(TUser, IEnumerable<String>)
Removes the specified user from the named roles.
Declaration
Task<IdentityResult> RemoveFromRolesAsync(TUser user, IEnumerable<string> roles)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to remove from the named roles. |
IEnumerable<System.String> | roles | The name of the roles to remove the user from. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The Task that represents the asynchronous operation, containing the IdentityResult of the operation. |
RemoveLoginAsync(TUser, String, String)
Attempts to remove the provided external login information from the specified user. and returns a flag indicating whether the removal succeed or not.
Declaration
Task<IdentityResult> RemoveLoginAsync(TUser user, string loginProvider, string providerKey)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to remove the login information from. |
System.String | loginProvider | The login provide whose information should be removed. |
System.String | providerKey | The key given by the external login provider for the specified user. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The System.Threading.Tasks.Task that represents the asynchronous operation, containing the Microsoft.AspNetCore.Identity.IdentityResult of the operation. |
ResetAccessFailedCountAsync(TUser)
Resets the access failed count for the user
Declaration
Task<IdentityResult> ResetAccessFailedCountAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user |
Returns
Type | Description |
---|---|
Task<IdentityResult> | A |
ResetPasswordAsync(TUser, String, String)
Resets the user
's password to the specified newPassword
after
validating the given password reset token
.
Declaration
Task<IdentityResult> ResetPasswordAsync(TUser user, string token, string newPassword)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose password should be reset. |
System.String | token | The password reset token to verify. |
System.String | newPassword | The new password to set if reset token verification succeeds. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The |
SetLockoutEndDateAsync(TUser, Nullable<DateTimeOffset>)
Locks out a user until the specified end date has passed. Setting a end date in the past immediately unlocks a user.
Declaration
Task<IdentityResult> SetLockoutEndDateAsync(TUser user, DateTimeOffset? lockoutEnd)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user whose lockout date should be set. |
System.Nullable<DateTimeOffset> | lockoutEnd | The |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The |
UpdateAsync(TUser)
Updates the specified user
in the backing store.
Declaration
Task<IdentityResult> UpdateAsync(TUser user)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to update. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | The |
ValidateCredentialsAsync(String, String)
Validates that a user's credentials are correct without actually logging them in.
Declaration
Task<bool> ValidateCredentialsAsync(string username, string password)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | The user name. |
System.String | password | The password. |
Returns
Type | Description |
---|---|
Task<System.Boolean> | True if the credentials are valid. |
ValidatePasswordAsync(String)
Used to validate the password without an identity user
Validation code is based on the default ValidatePasswordAsync code
Should return
Declaration
Task<IdentityResult> ValidatePasswordAsync(string password)
Parameters
Type | Name | Description |
---|---|---|
System.String | password | The password. |
Returns
Type | Description |
---|---|
Task<IdentityResult> | A |
ValidateSessionIdAsync(String, String)
Used to validate a user's session
Declaration
Task<bool> ValidateSessionIdAsync(string userId, string sessionId)
Parameters
Type | Name | Description |
---|---|---|
System.String | userId | |
System.String | sessionId |
Returns
Type | Description |
---|---|
Task<System.Boolean> | Returns true if the session is valid, otherwise false |
VerifyTwoFactorTokenAsync(TUser, String, String)
Verifies the specified two factor authentication token
against the user
.
Declaration
Task<bool> VerifyTwoFactorTokenAsync(TUser user, string tokenProvider, string token)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user the token is supposed to be for. |
System.String | tokenProvider | The provider which will verify the token. |
System.String | token | The token to verify. |
Returns
Type | Description |
---|---|
Task<System.Boolean> | The |
VerifyUserTokenAsync(TUser, String, String, String)
Returns a flag indicating whether the specified token
is valid for
the given user
and purpose
.
Declaration
Task<bool> VerifyUserTokenAsync(TUser user, string tokenProvider, string purpose, string token)
Parameters
Type | Name | Description |
---|---|---|
TUser | user | The user to validate the token against. |
System.String | tokenProvider | The token provider used to generate the token. |
System.String | purpose | The purpose the token should be generated for. |
System.String | token | The token to validate |
Returns
Type | Description |
---|---|
Task<System.Boolean> | The |