From dbec1c6236ac5cc6bc31db52686259c64c89a7d3 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Fri, 23 Sep 2016 11:59:15 -0700 Subject: [PATCH] Expose more for extensibility --- .../SignInManager.cs | 45 +++++++++++++++---- .../UserManager.cs | 38 ++++++++++++---- 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNetCore.Identity/SignInManager.cs b/src/Microsoft.AspNetCore.Identity/SignInManager.cs index c2034ab768..f959ea22c2 100644 --- a/src/Microsoft.AspNetCore.Identity/SignInManager.cs +++ b/src/Microsoft.AspNetCore.Identity/SignInManager.cs @@ -76,10 +76,20 @@ namespace Microsoft.AspNetCore.Identity /// protected internal UserManager UserManager { get; set; } - internal IUserClaimsPrincipalFactory ClaimsFactory { get; set; } - internal IdentityOptions Options { get; set; } + /// + /// The used. + /// + protected internal IUserClaimsPrincipalFactory ClaimsFactory { get; set; } - internal HttpContext Context { + /// + /// The used. + /// + protected internal IdentityOptions Options { get; set; } + + /// + /// The used. + /// + protected internal HttpContext Context { get { var context = _context ?? _contextAccessor?.HttpContext; @@ -95,7 +105,6 @@ namespace Microsoft.AspNetCore.Identity } } - /// /// Creates a for the specified , as an asynchronous operation. /// @@ -633,18 +642,33 @@ namespace Microsoft.AspNetCore.Identity return null; } - private async Task IsLockedOut(TUser user) + /// + /// Used to determine if a user is considered locked out. + /// + /// The user. + /// Whether a user is considered locked out. + protected virtual async Task IsLockedOut(TUser user) { return UserManager.SupportsUserLockout && await UserManager.IsLockedOutAsync(user); } - private async Task LockedOut(TUser user) + /// + /// Returns a locked out SignInResult. + /// + /// The user. + /// A locked out SignInResult + protected virtual async Task LockedOut(TUser user) { Logger.LogWarning(3, "User {userId} is currently locked out.", await UserManager.GetUserIdAsync(user)); return SignInResult.LockedOut; } - private async Task PreSignInCheck(TUser user) + /// + /// Used to ensure that a user is allowed to sign in. + /// + /// The user + /// Null if the user should be allowed to sign in, otherwise the SignInResult why they should be denied. + protected virtual async Task PreSignInCheck(TUser user) { if (!await CanSignInAsync(user)) { @@ -657,7 +681,12 @@ namespace Microsoft.AspNetCore.Identity return null; } - private Task ResetLockout(TUser user) + /// + /// Used to reset a user's lockout count. + /// + /// The user + /// The that represents the asynchronous operation, containing the of the operation. + protected virtual Task ResetLockout(TUser user) { if (UserManager.SupportsUserLockout) { diff --git a/src/Microsoft.AspNetCore.Identity/UserManager.cs b/src/Microsoft.AspNetCore.Identity/UserManager.cs index ae875bceb1..30881435c5 100644 --- a/src/Microsoft.AspNetCore.Identity/UserManager.cs +++ b/src/Microsoft.AspNetCore.Identity/UserManager.cs @@ -39,7 +39,11 @@ namespace Microsoft.AspNetCore.Identity private TimeSpan _defaultLockout = TimeSpan.Zero; private bool _disposed; private readonly HttpContext _context; - private CancellationToken CancellationToken => _context?.RequestAborted ?? CancellationToken.None; + + /// + /// The cancellation token assocated with the current HttpContext.RequestAborted or CancellationToken.None if unavailable. + /// + protected CancellationToken CancellationToken => _context?.RequestAborted ?? CancellationToken.None; /// /// Constructs a new instance of . @@ -110,24 +114,42 @@ namespace Microsoft.AspNetCore.Identity protected internal IUserStore Store { get; set; } /// - /// Gets the used to log messages from the manager. + /// The used to log messages from the manager. /// /// /// The used to log messages from the manager. /// protected internal virtual ILogger Logger { get; set; } - internal IPasswordHasher PasswordHasher { get; set; } + /// + /// The used to hash passwords. + /// + protected internal IPasswordHasher PasswordHasher { get; set; } - internal IList> UserValidators { get; } = new List>(); + /// + /// The used to validate users. + /// + protected internal IList> UserValidators { get; } = new List>(); - internal IList> PasswordValidators { get; } = new List>(); + /// + /// The used to validate passwords. + /// + protected internal IList> PasswordValidators { get; } = new List>(); - internal ILookupNormalizer KeyNormalizer { get; set; } + /// + /// The used to normalize things like user and role names. + /// + protected internal ILookupNormalizer KeyNormalizer { get; set; } - internal IdentityErrorDescriber ErrorDescriber { get; set; } + /// + /// The used to generate error messages. + /// + protected internal IdentityErrorDescriber ErrorDescriber { get; set; } - internal IdentityOptions Options { get; set; } + /// + /// The used to configure Identity. + /// + protected internal IdentityOptions Options { get; set; } /// /// Gets a flag indicating whether the backing user store supports authentication tokens.