SignInManager<TUser> Class

Summary

Provides the APIs for user sign in.

Syntax

public class SignInManager<TUser> where TUser : class

GitHub

View on GitHub

class Microsoft.AspNet.Identity.SignInManager<TUser>

Constructors

SignInManager(Microsoft.AspNet.Identity.UserManager<TUser>, IHttpContextAccessor, Microsoft.AspNet.Identity.IUserClaimsPrincipalFactory<TUser>, IOptions<Microsoft.AspNet.Identity.IdentityOptions>, ILogger<Microsoft.AspNet.Identity.SignInManager<TUser>>)

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

Arguments:
  • userManager (Microsoft.AspNet.Identity.UserManager{{TUser}}) – An instance of Microsoft.AspNet.Identity.SignInManager`1.UserManager used to retrieve users from and persist users.
  • contextAccessor (IHttpContextAccessor) – The accessor used to access the HttpContext.
  • claimsFactory (Microsoft.AspNet.Identity.IUserClaimsPrincipalFactory{{TUser}}) – The factory to use to create claims principals for a user.
  • optionsAccessor (IOptions{Microsoft.AspNet.Identity.IdentityOptions}) – The accessor used to access the Microsoft.AspNet.Identity.IdentityOptions.
  • logger (ILogger{Microsoft.AspNet.Identity.SignInManager`1}) – The logger used to log messages, warnings and errors.
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 provider.

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:

AuthenticationProperties

Returns:

A configured <see cref=”!:AuthenticationProperties” />.

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

Creates a System.Security.Claims.ClaimsPrincipal for the specified user, 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.AspNet.Identity.SignInResult}

Returns:

The task object representing the asynchronous operation containing the <see name=”SignInResult” /> 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 AuthenticationDescriptions for the known external login providers.

Return type:System.Collections.Generic.IEnumerable{AuthenticationDescription}
Returns:A collection of <see cref=”!:AuthenticationDescription” />s 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.AspNet.Identity.ExternalLoginInfo}

Returns:

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

public virtual Task<ExternalLoginInfo> GetExternalLoginInfoAsync(string expectedXsrf = null)
GetTwoFactorAuthenticationUserAsync()

Gets the TUser 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 <typeparamref name=”TUser” /> for the sign-in attempt.
public virtual Task<TUser> GetTwoFactorAuthenticationUserAsync()
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 userName and password 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.
Return type:

System.Threading.Tasks.Task{Microsoft.AspNet.Identity.SignInResult}

Returns:

The task object representing the asynchronous operation containing the <see name=”SignInResult” /> 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 user and password 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.AspNet.Identity.SignInResult}

Returns:

The task object representing the asynchronous operation containing the <see name=”SignInResult” /> 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, AuthenticationProperties, System.String)

Signs in the specified user.

Arguments:
  • user ({TUser}) – The user to sign-in.
  • authenticationProperties (AuthenticationProperties) – Properties applied to the login and authentication cookie.
  • 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, AuthenticationProperties authenticationProperties, string authenticationMethod = null)
SignInAsync(TUser, System.Boolean, System.String)

Signs in the specified user.

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.AspNet.Identity.SignInResult}

Returns:

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

public virtual Task<SignInResult> TwoFactorSignInAsync(string provider, string code, bool isPersistent, bool rememberClient)
ValidateSecurityStampAsync(System.Security.Claims.ClaimsPrincipal, System.String)

Validates the security stamp for the specified principal against the persisted stamp for the userId, as an asynchronous operation.

Arguments:
  • principal (System.Security.Claims.ClaimsPrincipal) – The principal whose stamp should be validated.
  • userId (System.String) – The ID for the user.
Return type:

System.Threading.Tasks.Task{{TUser}}

Returns:

The task object representing the asynchronous operation. The task will contain the <typeparamref name=”TUser” /> if the stamp matches the persisted value, otherwise it will return false.

public virtual Task<TUser> ValidateSecurityStampAsync(ClaimsPrincipal principal, string userId)

Properties

Logger()

Gets the ILogger used to log messages from the manager.

Return type:ILogger
protected virtual ILogger Logger { get; set; }