@@ -61,9 +61,9 @@ public SignInManager(UserManager<TUser> userManager,
61
61
}
62
62
63
63
private readonly IHttpContextAccessor _contextAccessor ;
64
- private HttpContext _context ;
65
64
private readonly IAuthenticationSchemeProvider _schemes ;
66
65
private readonly IUserConfirmation < TUser > _confirmation ;
66
+ private HttpContext ? _context ;
67
67
68
68
/// <summary>
69
69
/// Gets the <see cref="ILogger"/> used to log messages from the manager.
@@ -196,7 +196,7 @@ public virtual async Task RefreshSignInAsync(TUser user)
196
196
/// <param name="authenticationMethod">Name of the method used to authenticate the user.</param>
197
197
/// <returns>The task object representing the asynchronous operation.</returns>
198
198
[ SuppressMessage ( "ApiDesign" , "RS0026:Do not add multiple public overloads with optional parameters" , Justification = "Required for backwards compatibility" ) ]
199
- public virtual Task SignInAsync ( TUser user , bool isPersistent , string authenticationMethod = null )
199
+ public virtual Task SignInAsync ( TUser user , bool isPersistent , string ? authenticationMethod = null )
200
200
=> SignInAsync ( user , new AuthenticationProperties { IsPersistent = isPersistent } , authenticationMethod ) ;
201
201
202
202
/// <summary>
@@ -207,7 +207,7 @@ public virtual Task SignInAsync(TUser user, bool isPersistent, string authentica
207
207
/// <param name="authenticationMethod">Name of the method used to authenticate the user.</param>
208
208
/// <returns>The task object representing the asynchronous operation.</returns>
209
209
[ SuppressMessage ( "ApiDesign" , "RS0026:Do not add multiple public overloads with optional parameters" , Justification = "Required for backwards compatibility" ) ]
210
- public virtual Task SignInAsync ( TUser user , AuthenticationProperties authenticationProperties , string authenticationMethod = null )
210
+ public virtual Task SignInAsync ( TUser user , AuthenticationProperties authenticationProperties , string ? authenticationMethod = null )
211
211
{
212
212
IList < Claim > additionalClaims = Array . Empty < Claim > ( ) ;
213
213
if ( authenticationMethod != null )
@@ -235,7 +235,7 @@ public virtual Task SignInWithClaimsAsync(TUser user, bool isPersistent, IEnumer
235
235
/// <param name="authenticationProperties">Properties applied to the login and authentication cookie.</param>
236
236
/// <param name="additionalClaims">Additional claims that will be stored in the cookie.</param>
237
237
/// <returns>The task object representing the asynchronous operation.</returns>
238
- public virtual async Task SignInWithClaimsAsync ( TUser user , AuthenticationProperties authenticationProperties , IEnumerable < Claim > additionalClaims )
238
+ public virtual async Task SignInWithClaimsAsync ( TUser user , AuthenticationProperties ? authenticationProperties , IEnumerable < Claim > additionalClaims )
239
239
{
240
240
var userPrincipal = await CreateUserPrincipalAsync ( user ) ;
241
241
foreach ( var claim in additionalClaims )
@@ -264,7 +264,7 @@ public virtual async Task SignOutAsync()
264
264
/// <param name="principal">The principal whose stamp should be validated.</param>
265
265
/// <returns>The task object representing the asynchronous operation. The task will contain the <typeparamref name="TUser"/>
266
266
/// if the stamp matches the persisted value, otherwise it will return null.</returns>
267
- public virtual async Task < TUser > ValidateSecurityStampAsync ( ClaimsPrincipal principal )
267
+ public virtual async Task < TUser ? > ValidateSecurityStampAsync ( ClaimsPrincipal ? principal )
268
268
{
269
269
if ( principal == null )
270
270
{
@@ -287,7 +287,7 @@ public virtual async Task<TUser> ValidateSecurityStampAsync(ClaimsPrincipal prin
287
287
/// <param name="principal">The principal whose stamp should be validated.</param>
288
288
/// <returns>The task object representing the asynchronous operation. The task will contain the <typeparamref name="TUser"/>
289
289
/// if the stamp matches the persisted value, otherwise it will return null.</returns>
290
- public virtual async Task < TUser > ValidateTwoFactorSecurityStampAsync ( ClaimsPrincipal principal )
290
+ public virtual async Task < TUser ? > ValidateTwoFactorSecurityStampAsync ( ClaimsPrincipal ? principal )
291
291
{
292
292
if ( principal == null || principal . Identity ? . Name == null )
293
293
{
@@ -309,7 +309,7 @@ public virtual async Task<TUser> ValidateTwoFactorSecurityStampAsync(ClaimsPrinc
309
309
/// <param name="user">The user whose stamp should be validated.</param>
310
310
/// <param name="securityStamp">The expected security stamp value.</param>
311
311
/// <returns>The result of the validation.</returns>
312
- public virtual async Task < bool > ValidateSecurityStampAsync ( TUser user , string securityStamp )
312
+ public virtual async Task < bool > ValidateSecurityStampAsync ( TUser ? user , string ? securityStamp )
313
313
=> user != null &&
314
314
// Only validate the security stamp if the store supports it
315
315
( ! UserManager . SupportsUserSecurityStamp || securityStamp == await UserManager . GetSecurityStampAsync ( user ) ) ;
@@ -585,15 +585,15 @@ public virtual async Task<SignInResult> TwoFactorSignInAsync(string provider, st
585
585
/// </summary>
586
586
/// <returns>The task object representing the asynchronous operation containing the <typeparamref name="TUser"/>
587
587
/// for the sign-in attempt.</returns>
588
- public virtual async Task < TUser > GetTwoFactorAuthenticationUserAsync ( )
588
+ public virtual async Task < TUser ? > GetTwoFactorAuthenticationUserAsync ( )
589
589
{
590
590
var info = await RetrieveTwoFactorInfoAsync ( ) ;
591
591
if ( info == null )
592
592
{
593
593
return null ;
594
594
}
595
595
596
- return await UserManager . FindByIdAsync ( info . UserId ) ;
596
+ return await UserManager . FindByIdAsync ( info . UserId ! ) ;
597
597
}
598
598
599
599
/// <summary>
@@ -648,7 +648,7 @@ public virtual async Task<IEnumerable<AuthenticationScheme>> GetExternalAuthenti
648
648
/// <param name="expectedXsrf">Flag indication whether a Cross Site Request Forgery token was expected in the current request.</param>
649
649
/// <returns>The task object representing the asynchronous operation containing the <see name="ExternalLoginInfo"/>
650
650
/// for the sign-in attempt.</returns>
651
- public virtual async Task < ExternalLoginInfo > GetExternalLoginInfoAsync ( string expectedXsrf = null )
651
+ public virtual async Task < ExternalLoginInfo ? > GetExternalLoginInfoAsync ( string ? expectedXsrf = null )
652
652
{
653
653
var auth = await Context . AuthenticateAsync ( IdentityConstants . ExternalScheme ) ;
654
654
var items = auth ? . Properties ? . Items ;
@@ -681,7 +681,7 @@ public virtual async Task<ExternalLoginInfo> GetExternalLoginInfoAsync(string ex
681
681
?? provider ;
682
682
return new ExternalLoginInfo ( auth . Principal , provider , providerKey , providerDisplayName )
683
683
{
684
- AuthenticationTokens = auth . Properties . GetTokens ( ) ,
684
+ AuthenticationTokens = auth . Properties ? . GetTokens ( ) ,
685
685
AuthenticationProperties = auth . Properties
686
686
} ;
687
687
}
@@ -726,7 +726,7 @@ public virtual async Task<IdentityResult> UpdateExternalAuthenticationTokensAsyn
726
726
/// <param name="redirectUrl">The external login URL users should be redirected to during the login flow.</param>
727
727
/// <param name="userId">The current user's identifier, which will be used to provide CSRF protection.</param>
728
728
/// <returns>A configured <see cref="AuthenticationProperties"/>.</returns>
729
- public virtual AuthenticationProperties ConfigureExternalAuthenticationProperties ( string provider , string redirectUrl , string userId = null )
729
+ public virtual AuthenticationProperties ConfigureExternalAuthenticationProperties ( string ? provider , string ? redirectUrl , string ? userId = null )
730
730
{
731
731
var properties = new AuthenticationProperties { RedirectUri = redirectUrl } ;
732
732
properties . Items [ LoginProviderKey ] = provider ;
@@ -743,7 +743,7 @@ public virtual AuthenticationProperties ConfigureExternalAuthenticationPropertie
743
743
/// <param name="userId">The user whose is logging in via 2fa.</param>
744
744
/// <param name="loginProvider">The 2fa provider.</param>
745
745
/// <returns>A <see cref="ClaimsPrincipal"/> containing the user 2fa information.</returns>
746
- internal static ClaimsPrincipal StoreTwoFactorInfo ( string userId , string loginProvider )
746
+ internal static ClaimsPrincipal StoreTwoFactorInfo ( string userId , string ? loginProvider )
747
747
{
748
748
var identity = new ClaimsIdentity ( IdentityConstants . TwoFactorUserIdScheme ) ;
749
749
identity . AddClaim ( new Claim ( ClaimTypes . Name , userId ) ) ;
@@ -781,7 +781,7 @@ await UserManager.GetTwoFactorEnabledAsync(user) &&
781
781
/// <param name="loginProvider">The login provider to use. Default is null</param>
782
782
/// <param name="bypassTwoFactor">Flag indicating whether to bypass two factor authentication. Default is false</param>
783
783
/// <returns>Returns a <see cref="SignInResult"/></returns>
784
- protected virtual async Task < SignInResult > SignInOrTwoFactorAsync ( TUser user , bool isPersistent , string loginProvider = null , bool bypassTwoFactor = false )
784
+ protected virtual async Task < SignInResult > SignInOrTwoFactorAsync ( TUser user , bool isPersistent , string ? loginProvider = null , bool bypassTwoFactor = false )
785
785
{
786
786
if ( ! bypassTwoFactor && await IsTfaEnabled ( user ) )
787
787
{
@@ -809,7 +809,7 @@ protected virtual async Task<SignInResult> SignInOrTwoFactorAsync(TUser user, bo
809
809
return SignInResult . Success ;
810
810
}
811
811
812
- private async Task < TwoFactorAuthenticationInfo > RetrieveTwoFactorInfoAsync ( )
812
+ private async Task < TwoFactorAuthenticationInfo ? > RetrieveTwoFactorInfoAsync ( )
813
813
{
814
814
var result = await Context . AuthenticateAsync ( IdentityConstants . TwoFactorUserIdScheme ) ;
815
815
if ( result ? . Principal != null )
@@ -849,7 +849,7 @@ protected virtual Task<SignInResult> LockedOut(TUser user)
849
849
/// </summary>
850
850
/// <param name="user">The user</param>
851
851
/// <returns>Null if the user should be allowed to sign in, otherwise the SignInResult why they should be denied.</returns>
852
- protected virtual async Task < SignInResult > PreSignInCheck ( TUser user )
852
+ protected virtual async Task < SignInResult ? > PreSignInCheck ( TUser user )
853
853
{
854
854
if ( ! await CanSignInAsync ( user ) )
855
855
{
@@ -876,9 +876,9 @@ protected virtual Task ResetLockout(TUser user)
876
876
return Task . CompletedTask ;
877
877
}
878
878
879
- internal class TwoFactorAuthenticationInfo
879
+ internal sealed class TwoFactorAuthenticationInfo
880
880
{
881
- public string UserId { get ; set ; }
882
- public string LoginProvider { get ; set ; }
881
+ public string ? UserId { get ; set ; }
882
+ public string ? LoginProvider { get ; set ; }
883
883
}
884
884
}
0 commit comments