Skip to content

Commit c802134

Browse files
martincostelloTratcher
authored andcommitted
Use ISystemClock for request timestamps (#18124)
Use ISystemClock to generate timestamps for Twitter authentication. Remove custom static field for the epoch.
1 parent df33890 commit c802134

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/Security/Authentication/Twitter/src/TwitterHandler.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ namespace Microsoft.AspNetCore.Authentication.Twitter
2121
{
2222
public class TwitterHandler : RemoteAuthenticationHandler<TwitterOptions>
2323
{
24-
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
25-
2624
private HttpClient Backchannel => Options.Backchannel;
2725

2826
/// <summary>
@@ -301,9 +299,9 @@ private async Task<JsonDocument> RetrieveUserDetailsAsync(AccessToken accessToke
301299
return result;
302300
}
303301

304-
private static string GenerateTimeStamp()
302+
private string GenerateTimeStamp()
305303
{
306-
var secondsSinceUnixEpocStart = DateTime.UtcNow - Epoch;
304+
var secondsSinceUnixEpocStart = Clock.UtcNow - DateTimeOffset.UnixEpoch;
307305
return Convert.ToInt64(secondsSinceUnixEpocStart.TotalSeconds).ToString(CultureInfo.InvariantCulture);
308306
}
309307

0 commit comments

Comments
 (0)