SignInManager<TUser> Class

Provides the APIs for user sign in.

Namespace
Microsoft.AspNetCore.Identity
Assemblies
  • Microsoft.AspNetCore.Identity

Syntax

public class SignInManager<TUser>
    where TUser : class
class Microsoft.AspNetCore.Identity.SignInManager<TUser>

Constructors

SignInManager(Microsoft.AspNetCore.Identity.UserManager<TUser>, Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory<TUser>, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Builder.IdentityOptions>, Microsoft.Extensions.Logging.ILogger<Microsoft.AspNetCore.Identity.SignInManager<TUser>>)

Creates a new instance of Microsoft.AspNetCore.Identity.SignInManager`1.

Arguments:
public SignInManager(UserManager<TUser> userManager, IHttpContextAccessor contextAccessor, IUserClaimsPrincipalFactory<TUser> claimsFactory, IOptions<IdentityOptions> optionsAccessor, ILogger<SignInManager<TUser>> logger)

Methods

CanSignInAsync(TUser)

Returns a flag indicating whether the specified user can sign in.

Arguments:user (TUser) – The user whose sign-in status should be returned.
Return type:System.Threading.Tasks.Task<System.Boolean>
Returns:The task object representing the asynchronous operation, containing a flag that is true if the specified user can sign-in, otherwise false.
public virtual Task<bool> CanSignInAsync(TUser user)
ConfigureExternalAuthenticationProperties(System.String, System.String, System.String)

Configures the redirect URL and user identifier for the specified external login <em>provider</em>.

Arguments:
  • provider (System.String) – The provider to configure.
  • redirectUrl (System.String) – The external login URL users should be redirected to during the login glow.
  • userId (System.String) – The current user’s identifier, which will be used to provide CSRF protection.
Return type:

Microsoft.AspNetCore.Http.Authentication.AuthenticationProperties

Returns:

A configured Microsoft.AspNetCore.Http.Authentication.AuthenticationProperties.

public virtual AuthenticationProperties ConfigureExternalAuthenticationProperties(string provider, string redirectUrl, string userId = null)
CreateUserPrincipalAsync(TUser)

Creates a System.Security.Claims.ClaimsPrincipal for the specified <em>user</em>, as an asynchronous operation.

Arguments:user (TUser) – The user to create a System.Security.Claims.ClaimsPrincipal for.
Return type:System.Threading.Tasks.Task<System.Security.Claims.ClaimsPrincipal>
Returns:The task object representing the asynchronous operation, containing the ClaimsPrincipal for the specified user.
public virtual Task<ClaimsPrincipal> CreateUserPrincipalAsync(TUser user)
ExternalLoginSignInAsync(System.String, System.String, System.Boolean)

Signs in a user via a previously registered third party login, as an asynchronous operation.

Arguments:
  • loginProvider (System.String) – The login provider to use.
  • providerKey (System.String) – The unique provider identifier for the user.
  • isPersistent (System.Boolean) – Flag indicating whether the sign-in cookie should persist after the browser is closed.
Return type:

System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.SignInResult>

Returns:

The task object representing the asynchronous operation containing the <see name=”SignInResult”></see> for the sign-in attempt.

public virtual Task<SignInResult> ExternalLoginSignInAsync(string loginProvider, string providerKey, bool isPersistent)
ForgetTwoFactorClientAsync()

Clears the “Remember this browser flag” from the current browser, as an asynchronous operation.

Return type:System.Threading.Tasks.Task
Returns:The task object representing the asynchronous operation.
public virtual Task ForgetTwoFactorClientAsync()
GetExternalAuthenticationSchemes()

Gets a collection of Microsoft.AspNetCore.Http.Authentication.AuthenticationDescriptions for the known external login providers.

Return type:System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Http.Authentication.AuthenticationDescription>
Returns:A collection of Microsoft.AspNetCore.Http.Authentication.AuthenticationDescriptions for the known external login providers.
public virtual IEnumerable<AuthenticationDescription> GetExternalAuthenticationSchemes()
GetExternalLoginInfoAsync(System.String)

Gets the external login information for the current login, as an asynchronous operation.

Arguments:expectedXsrf (System.String) – Flag indication whether a Cross Site Request Forgery token was expected in the current request.
Return type:System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.ExternalLoginInfo>
Returns:The task object representing the asynchronous operation containing the <see name=”ExternalLoginInfo”></see> for the sign-in attempt.
public virtual Task<ExternalLoginInfo> GetExternalLoginInfoAsync(string expectedXsrf = null)
GetTwoFactorAuthenticationUserAsync()

Gets the <em>TUser</em> for the current two factor authentication login, as an asynchronous operation.

Return type:System.Threading.Tasks.Task<TUser>
Returns:The task object representing the asynchronous operation containing the <em>TUser</em> for the sign-in attempt.
public virtual Task<TUser> GetTwoFactorAuthenticationUserAsync()
IsSignedIn(System.Security.Claims.ClaimsPrincipal)

Returns true if the principal has an identity with the application cookie identity

Arguments:principal (System.Security.Claims.ClaimsPrincipal) – The System.Security.Claims.ClaimsPrincipal instance.
Return type:System.Boolean
Returns:True if the user is logged in with identity.
public virtual bool IsSignedIn(ClaimsPrincipal principal)
IsTwoFactorClientRememberedAsync(TUser)

Returns a flag indicating if the current client browser has been remembered by two factor authentication for the user attempting to login, as an asynchronous operation.

Arguments:user (TUser) – The user attempting to login.
Return type:System.Threading.Tasks.Task<System.Boolean>
Returns:The task object representing the asynchronous operation containing true if the browser has been remembered for the current user.
public virtual Task<bool> IsTwoFactorClientRememberedAsync(TUser user)
PasswordSignInAsync(System.String, System.String, System.Boolean, System.Boolean)

Attempts to sign in the specified <em>userName</em> and <em>password</em> combination as an asynchronous operation.

Arguments:
  • userName (System.String) – The user name to sign in.
  • password (System.String) – The password to attempt to sign in with.
  • isPersistent (System.Boolean) – Flag indicating whether the sign-in cookie should persist after the browser is closed.
  • lockoutOnFailure (System.Boolean) – Flag indicating if the user account should be locked if the sign in fails.
Return type:

System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.SignInResult>

Returns:

The task object representing the asynchronous operation containing the <see name=”SignInResult”></see> for the sign-in attempt.

public virtual Task<SignInResult> PasswordSignInAsync(string userName, string password, bool isPersistent, bool lockoutOnFailure)
PasswordSignInAsync(TUser, System.String, System.Boolean, System.Boolean)

Attempts to sign in the specified <em>user</em> and <em>password</em> combination as an asynchronous operation.

Arguments:
  • user (TUser) – The user to sign in.
  • password (System.String) – The password to attempt to sign in with.
  • isPersistent (System.Boolean) – Flag indicating whether the sign-in cookie should persist after the browser is closed.
  • lockoutOnFailure (System.Boolean) – Flag indicating if the user account should be locked if the sign in fails.
Return type:

System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.SignInResult>

Returns:

The task object representing the asynchronous operation containing the <see name=”SignInResult”></see> for the sign-in attempt.

public virtual Task<SignInResult> PasswordSignInAsync(TUser user, string password, bool isPersistent, bool lockoutOnFailure)
RefreshSignInAsync(TUser)

Regenerates the user’s application cookie, whilst preserving the existing AuthenticationProperties like rememberMe, as an asynchronous operation.

Arguments:user (TUser) – The user whose sign-in cookie should be refreshed.
Return type:System.Threading.Tasks.Task
Returns:The task object representing the asynchronous operation.
public virtual Task RefreshSignInAsync(TUser user)
RememberTwoFactorClientAsync(TUser)

Sets a flag on the browser to indicate the user has selected “Remember this browser” for two factor authentication purposes, as an asynchronous operation.

Arguments:user (TUser) – The user who choose “remember this browser”.
Return type:System.Threading.Tasks.Task
Returns:The task object representing the asynchronous operation.
public virtual Task RememberTwoFactorClientAsync(TUser user)
SignInAsync(TUser, Microsoft.AspNetCore.Http.Authentication.AuthenticationProperties, System.String)

Signs in the specified <em>user</em>.

Arguments:
Return type:

System.Threading.Tasks.Task

Returns:

The task object representing the asynchronous operation.

public virtual Task SignInAsync(TUser user, AuthenticationProperties authenticationProperties, string authenticationMethod = null)
SignInAsync(TUser, System.Boolean, System.String)

Signs in the specified <em>user</em>.

Arguments:
  • user (TUser) – The user to sign-in.
  • isPersistent (System.Boolean) – Flag indicating whether the sign-in cookie should persist after the browser is closed.
  • authenticationMethod (System.String) – Name of the method used to authenticate the user.
Return type:

System.Threading.Tasks.Task

Returns:

The task object representing the asynchronous operation.

public virtual Task SignInAsync(TUser user, bool isPersistent, string authenticationMethod = null)
SignOutAsync()

Signs the current user out of the application.

Return type:System.Threading.Tasks.Task
public virtual Task SignOutAsync()
TwoFactorSignInAsync(System.String, System.String, System.Boolean, System.Boolean)

Validates the two faction sign in code and creates and signs in the user, as an asynchronous operation.

Arguments:
  • provider (System.String) – The two factor authentication provider to validate the code against.
  • code (System.String) – The two factor authentication code to validate.
  • isPersistent (System.Boolean) – Flag indicating whether the sign-in cookie should persist after the browser is closed.
  • rememberClient (System.Boolean) – Flag indicating whether the current browser should be remember, suppressing all further two factor authentication prompts.
Return type:

System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.SignInResult>

Returns:

The task object representing the asynchronous operation containing the <see name=”SignInResult”></see> for the sign-in attempt.

public virtual Task<SignInResult> TwoFactorSignInAsync(string provider, string code, bool isPersistent, bool rememberClient)
UpdateExternalAuthenticationTokensAsync(Microsoft.AspNetCore.Identity.ExternalLoginInfo)

Stores any authentication tokens found in the external authentication cookie into the associated user.

Arguments:externalLogin (Microsoft.AspNetCore.Identity.ExternalLoginInfo) – The information from the external login provider.
Return type:System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.IdentityResult>
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation, containing the Microsoft.AspNetCore.Identity.IdentityResult of the operation.
public virtual Task<IdentityResult> UpdateExternalAuthenticationTokensAsync(ExternalLoginInfo externalLogin)
ValidateSecurityStampAsync(System.Security.Claims.ClaimsPrincipal)

Validates the security stamp for the specified <em>principal</em> against the persisted stamp for the current user, as an asynchronous operation.

Arguments:principal (System.Security.Claims.ClaimsPrincipal) – The principal whose stamp should be validated.
Return type:System.Threading.Tasks.Task<TUser>
Returns:The task object representing the asynchronous operation. The task will contain the <em>TUser</em> if the stamp matches the persisted value, otherwise it will return false.
public virtual Task<TUser> ValidateSecurityStampAsync(ClaimsPrincipal principal)

Properties

Microsoft.AspNetCore.Identity.SignInManager<TUser>.Logger

Gets the Microsoft.Extensions.Logging.ILogger used to log messages from the manager.

Return type:Microsoft.Extensions.Logging.ILogger
Returns:The Microsoft.Extensions.Logging.ILogger used to log messages from the manager.
protected virtual ILogger Logger { get; set; }
Microsoft.AspNetCore.Identity.SignInManager<TUser>.UserManager
Return type:Microsoft.AspNetCore.Identity.UserManager<TUser>
protected UserManager<TUser> UserManager { get; set; }