@@ -23,16 +23,52 @@ public class SecurityStampValidator<TUser> : ISecurityStampValidator where TUser
23
23
/// <param name="signInManager">The <see cref="SignInManager{TUser}"/>.</param>
24
24
/// <param name="clock">The system clock.</param>
25
25
/// <param name="logger">The logger.</param>
26
+ [ Obsolete ( "ISystemClock is obsolete, use TimeProvider instead." ) ]
26
27
public SecurityStampValidator ( IOptions < SecurityStampValidatorOptions > options , SignInManager < TUser > signInManager , ISystemClock clock , ILoggerFactory logger )
27
28
{
28
29
ArgumentNullException . ThrowIfNull ( options ) ;
29
30
ArgumentNullException . ThrowIfNull ( signInManager ) ;
30
31
SignInManager = signInManager ;
31
32
Options = options . Value ;
33
+ Time = new TimeClockProvider ( clock ) ;
32
34
Clock = clock ;
33
35
Logger = logger . CreateLogger ( GetType ( ) ) ;
34
36
}
35
37
38
+ /// <summary>
39
+ /// Creates a new instance of <see cref="SecurityStampValidator{TUser}"/>.
40
+ /// </summary>
41
+ /// <param name="options">Used to access the <see cref="IdentityOptions"/>.</param>
42
+ /// <param name="signInManager">The <see cref="SignInManager{TUser}"/>.</param>
43
+ /// <param name="clock">The system clock.</param>
44
+ /// <param name="time">The system clock.</param>
45
+ /// <param name="logger">The logger.</param>
46
+ [ Obsolete ( "ISystemClock is obsolete, use TimeProvider instead." ) ]
47
+ public SecurityStampValidator ( IOptions < SecurityStampValidatorOptions > options , SignInManager < TUser > signInManager , ISystemClock clock , ILoggerFactory logger , TimeProvider time )
48
+ : this ( options , signInManager , time , logger )
49
+ {
50
+ }
51
+
52
+ /// <summary>
53
+ /// Creates a new instance of <see cref="SecurityStampValidator{TUser}"/>.
54
+ /// </summary>
55
+ /// <param name="options">Used to access the <see cref="IdentityOptions"/>.</param>
56
+ /// <param name="signInManager">The <see cref="SignInManager{TUser}"/>.</param>
57
+ /// <param name="time">The system clock.</param>
58
+ /// <param name="logger">The logger.</param>
59
+ public SecurityStampValidator ( IOptions < SecurityStampValidatorOptions > options , SignInManager < TUser > signInManager , TimeProvider time , ILoggerFactory logger )
60
+ {
61
+ ArgumentNullException . ThrowIfNull ( options ) ;
62
+ ArgumentNullException . ThrowIfNull ( signInManager ) ;
63
+ SignInManager = signInManager ;
64
+ Options = options . Value ;
65
+ Time = time ;
66
+ #pragma warning disable CS0618 // Type or member is obsolete
67
+ Clock = new SystemClock ( time ) ;
68
+ #pragma warning restore CS0618 // Type or member is obsolete
69
+ Logger = logger . CreateLogger ( GetType ( ) ) ;
70
+ }
71
+
36
72
/// <summary>
37
73
/// The SignInManager.
38
74
/// </summary>
@@ -46,8 +82,14 @@ public SecurityStampValidator(IOptions<SecurityStampValidatorOptions> options, S
46
82
/// <summary>
47
83
/// The <see cref="ISystemClock"/>.
48
84
/// </summary>
85
+ [ Obsolete ( "ISystemClock is obsolete, use TimeProvider instead." ) ]
49
86
public ISystemClock Clock { get ; }
50
87
88
+ /// <summary>
89
+ /// The <see cref="ISystemClock"/>.
90
+ /// </summary>
91
+ public TimeProvider Time { get ; }
92
+
51
93
/// <summary>
52
94
/// Gets the <see cref="ILogger"/> used to log messages.
53
95
/// </summary>
@@ -87,7 +129,7 @@ protected virtual async Task SecurityStampVerified(TUser user, CookieValidatePri
87
129
{
88
130
// On renewal calculate the new ticket length relative to now to avoid
89
131
// extending the expiration.
90
- context . Properties . IssuedUtc = Clock . UtcNow ;
132
+ context . Properties . IssuedUtc = Time . GetUtcNow ( ) ;
91
133
}
92
134
}
93
135
@@ -109,9 +151,9 @@ protected virtual async Task SecurityStampVerified(TUser user, CookieValidatePri
109
151
public virtual async Task ValidateAsync ( CookieValidatePrincipalContext context )
110
152
{
111
153
var currentUtc = DateTimeOffset . UtcNow ;
112
- if ( Clock != null )
154
+ if ( Time != null )
113
155
{
114
- currentUtc = Clock . UtcNow ;
156
+ currentUtc = Time . GetUtcNow ( ) ;
115
157
}
116
158
var issuedUtc = context . Properties . IssuedUtc ;
117
159
0 commit comments