dotnet / dotnet/aspnetcore

Use TimeProvider instead of DateTimeOffset in DataProtectionAPI

Open
#57,833 2 comments 3 reactions 0 assignees View on GitHub
area-dataprotection
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

I am trying to integration test my application which uses the DataProtectionAPI to encrypt user session data. My tests should also cover some time-related aspects. Therefore I am using the [TimeProvider](https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider?view=net-8.0) and [FakeTimeProvider](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.time.testing.faketimeprovider?view=net-8.0) which where introduced with Dotnet8. Unfortunately, the DataProtectionAPI still uses the static DateTimeOffset instead of the new TimeProvider and therefore does not react to time changes in my tests.

### Describe the solution you'd like

Replace the DateTimeOffset class with the TimeProvider to determine the current time in the DataProtectionAPI implementation

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.