Skip to content

Onboard aspnetcore into the new TimeProvider type from runtime #47472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
7 tasks done
joperezr opened this issue Mar 28, 2023 · 10 comments · Fixed by #48081
Closed
7 tasks done

Onboard aspnetcore into the new TimeProvider type from runtime #47472

joperezr opened this issue Mar 28, 2023 · 10 comments · Fixed by #48081
Assignees
Labels
api-approved API was approved in API review, it can be implemented area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Milestone

Comments

@joperezr
Copy link
Member

joperezr commented Mar 28, 2023

Now that TimeProvider has been added to the platform in dotnet/runtime#83604, we should make the following changes in the aspnetcore layer for .NET 8:

  • Remove all the copies of ISystemClock that exist in the repo (there are at least 6, with types that implement them), particularly all the ones that are not publicly exposed, and replace the places where they are used with TimeProvider.
  • Two of these copies of ISystemClock are actually public and part of some of our API surface: Microsoft.AspNetCore.Authentication.ISystemClock, and Microsoft.AspNetCore.Server.kestrel.Core.Internal.Infrastructure.ISystemClock. We should consider deprecating those as well as the affected API that exposes them, and consider if there are new APIs/overloads that should be exposed that use TimeProvider as opposed to ISystemClock.

cc: @tarekgh @Tratcher @adityamandaleeka @davidfowl @mkArtakMSFT

@joperezr joperezr added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 28, 2023
@ghost ghost added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Mar 28, 2023
@joperezr joperezr removed the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 28, 2023
@joperezr
Copy link
Member Author

Not sure if area-infrastructure is the right label for this, but given it is spread across multiple parts of the repo I'll let others triage appropriately.

@joperezr joperezr added this to the .NET 8.0 milestone Mar 28, 2023
@davidfowl davidfowl removed the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Mar 28, 2023
@Tratcher
Copy link
Member

Tratcher commented Mar 28, 2023

@SebastianC was going to look at this. Woops, sorry.

I'm interested, but will be busy for a few weeks.

@davidfowl
Copy link
Member

I think you meant @sebastienros 😄

@BrennanConroy
Copy link
Member

We should also be aware of #13628 when doing this. I don't know if this work will make it easier or harder to convert Kestrel to wall clock (except for the Date header obviously)

@Tratcher
Copy link
Member

Follow up:
Microsoft.Extensions.Internal.ISystemClock used by MemoryCacheOptions.Clock, used in CertificateValidationCache.

@Tratcher

This comment was marked as duplicate.

@halter73 halter73 added the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Apr 17, 2023
@halter73
Copy link
Member

halter73 commented Apr 17, 2023

API Review Notes:

Proposed API

ISystemClock and SystemClock are now obsolete.

namespace Microsoft.AspNetCore.Authentication;

+ [Obsolete]
public interface ISystemClock
{
}

+ [Obsolete]
public class SystemClock : ISystemClock
{
}

Each auth handler and security token validator is obsoleting the existing constructor and adding a new one without ISystemClock. Their Clock property is now obsolete and replaced by TimeProvider. TimeProvider can now be set via options or via DI (IPostConfigureOptions).

public AuthenticationHandler<TOptions>
{
+ [Obsolete]
  protected AuthenticationHandler(IOptionsMonitor<TOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
+ protected AuthenticationHandler(IOptionsMonitor<TOptions> options, ILoggerFactory logger, UrlEncoder encoder)
+ [Obsolete]
  public ISystemClock Clock { get; }
+ public TimeProvider TimeProvider { get; }
}
public AuthenticaitonSchemeOptions
{
+ public TimeProvider? TimeProvider { get; set; }
}

public SecuirtyTokenValidator
{
+ [Obsolete]
  public SecurityStampValidator(IOptions<SecurityStampValidatorOptions> options, SignInManager<TUser> signInManager, ISystemClock clock, ILoggerFactory logger)
+ public SecurityStampValidator(IOptions<SecurityStampValidatorOptions> options, SignInManager<TUser> signInManager, ILoggerFactory logger)
+ [Obsolete]
  public ISystemClock Clock { get; }
+ public TimeProvider TimeProvider { get; }
}
public SecurityStampValidatorOptions
{
+ public TimeProvider? TimeProvider { get; set; }
}

  • What do we think about the pattern of adding a new obsolete constructor?
    • [EditorBrowsable(Never)]? It could help with the OAuthHandler in particular when the derived types call base.
  • What's the plan after .NET 8?
    • Remove default ISystemClock registration in AddAuthentication. Maybe keep the interface around for people who add it manually.
  • Can we teach DI not to use [Obsolete] constructors
    • We'd have to change the contract for third-party DI containers to do the same. We cannot design an API expecting that feature right now.
  • Can we add a TimeProvider property to AuthenticationSchemeOptions instead of adding the TimeProvider directly to DI?
    • This could make it harder to replace the TimerProvider globally for every scheme.

We'd prefer not to add new obsolete constructor to every auth handler if possible, but we don't like any of the other alternatives.

API Approved! (@Tratcher plans to fill in the "Proposed API" section above)

Updated proposal.

@halter73 halter73 added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels Apr 17, 2023
@davidfowl
Copy link
Member

Why is the property and argument name "time" instead of "timeProvider"

@Tratcher Tratcher removed the api-approved API was approved in API review, it can be implemented label Apr 18, 2023
@halter73 halter73 added the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Apr 24, 2023
@ghost
Copy link

ghost commented Apr 24, 2023

Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:

  • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
  • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
  • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.

@halter73
Copy link
Member

halter73 commented May 1, 2023

API Review Notes:

  • We removed the TimeProvider accepting constructors from auth and identity and use properties on options instead.
  • What do we think about TimeProvider being nullable instead of preset to TimeProvider.System?
    • Nullable makes it more obvious if it's been overridden.
  • Do we like TimeProvider over Time for the property names? Yes.
  • No namespace were modified.
namespace Microsoft.AspNetCore.Authentication;

+ [Obsolete]
public interface ISystemClock
{
}

+ [Obsolete]
public class SystemClock : ISystemClock
{
}

public AuthenticationHandler<TOptions>
{
+ [Obsolete]
  protected AuthenticationHandler(IOptionsMonitor<TOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
+ protected AuthenticationHandler(IOptionsMonitor<TOptions> options, ILoggerFactory logger, UrlEncoder encoder)
+ [Obsolete]
  public ISystemClock Clock { get; }
+ public TimeProvider TimeProvider { get; }
}

public AuthenticaitonSchemeOptions
{
+ public TimeProvider? TimeProvider { get; set; }
}

public SecuirtyTokenValidator
{
+ [Obsolete]
  public SecurityStampValidator(IOptions<SecurityStampValidatorOptions> options, SignInManager<TUser> signInManager, ISystemClock clock, ILoggerFactory logger)
+ public SecurityStampValidator(IOptions<SecurityStampValidatorOptions> options, SignInManager<TUser> signInManager, ILoggerFactory logger)
+ [Obsolete]
  public ISystemClock Clock { get; }
+ public TimeProvider TimeProvider { get; }
}

public SecurityStampValidatorOptions
{
+ public TimeProvider? TimeProvider { get; set; }
}

API Approved as updated!

@halter73 halter73 added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels May 1, 2023
@Tratcher Tratcher modified the milestones: .NET 8.0, 8.0-preview5 May 16, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 18, 2023
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
@halter73 @davidfowl @Tratcher @BrennanConroy @amcasey @joperezr and others