aspnetcore/src/Microsoft.AspNetCore.Authen.../SystemClock.cs

28 lines
1004 B
C#

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.AspNetCore.Authentication
{
/// <summary>
/// Provides access to the normal system clock with precision in seconds.
/// </summary>
public class SystemClock : ISystemClock
{
/// <summary>
/// Retrieves the current system time in UTC.
/// </summary>
public DateTimeOffset UtcNow
{
get
{
// the clock measures whole seconds only, to have integral expires_in results, and
// because milliseconds do not round-trip serialization formats
var utcNowPrecisionSeconds = new DateTime((DateTime.UtcNow.Ticks / TimeSpan.TicksPerSecond) * TimeSpan.TicksPerSecond, DateTimeKind.Utc);
return new DateTimeOffset(utcNowPrecisionSeconds);
}
}
}
}