Use ISystemClock for request timestamps (#18124)

Use ISystemClock to generate timestamps for Twitter authentication.
Remove custom static field for the epoch.
This commit is contained in:
Martin Costello 2020-01-04 20:39:24 +00:00 committed by Chris Ross
parent df33890548
commit c802134737
1 changed files with 2 additions and 4 deletions

View File

@ -21,8 +21,6 @@ namespace Microsoft.AspNetCore.Authentication.Twitter
{
public class TwitterHandler : RemoteAuthenticationHandler<TwitterOptions>
{
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
private HttpClient Backchannel => Options.Backchannel;
/// <summary>
@ -301,9 +299,9 @@ namespace Microsoft.AspNetCore.Authentication.Twitter
return result;
}
private static string GenerateTimeStamp()
private string GenerateTimeStamp()
{
var secondsSinceUnixEpocStart = DateTime.UtcNow - Epoch;
var secondsSinceUnixEpocStart = Clock.UtcNow - DateTimeOffset.UnixEpoch;
return Convert.ToInt64(secondsSinceUnixEpocStart.TotalSeconds).ToString(CultureInfo.InvariantCulture);
}