Skip to content

Use TimeProvider instead of DateTime ambient context #2572

@alexmurari

Description

@alexmurari

Currently, token lifetime validation is performed by getting the current time from a DateTime ambient context, as seen here.

(I know there's other places where DateTime is used to get the current time, this is just an example)

This leads to flaky, non-deterministic tests, as there's no control of the current time whatsoever.

With the introduction of TimeProvider in .NET 8, there's an out-of-the-box solution for abstracting time.

My proposal here is adopt TimeProvider instead of relying directly on static DateTime class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions