Identity: Use TimeProvider for Passkey CreatedAt#66569
Open
Vladik29w wants to merge 3 commits intodotnet:mainfrom
Open
Identity: Use TimeProvider for Passkey CreatedAt#66569Vladik29w wants to merge 3 commits intodotnet:mainfrom
Vladik29w wants to merge 3 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates ASP.NET Core Identity’s passkey registration flow to respect a TimeProvider (when available) instead of hardcoding DateTime.UtcNow for the passkey CreatedAt timestamp, enabling deterministic time-dependent tests.
Changes:
- Update
PasskeyHandlerto obtain the current UTC time viaTimeProviderresolved from request services (with fallback). - Add/adjust unit test coverage to validate
CreatedAtis sourced from a fakeTimeProvider.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Identity/Core/src/PasskeyHandler.cs | Uses TimeProvider (via HttpContext.RequestServices) when setting UserPasskeyInfo.CreatedAt. |
| src/Identity/test/Identity.Test/Passkeys/PasskeyHandlerAttestationTest.cs | Adds a test that sets a fake time provider and asserts CreatedAt matches it. |
Comment on lines
+682
to
+683
| private static DateTime GetUtcNow(HttpContext httpContext) | ||
| => (httpContext.RequestServices.GetService<TimeProvider>() ?? TimeProvider.System).GetUtcNow().UtcDateTime; |
Author
|
@dotnet-policy-service agree |
Contributor
|
Thanks for your PR, @Vladik29w. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Youssef1313
reviewed
May 2, 2026
Youssef1313
reviewed
May 2, 2026
Co-authored-by: Youssef Fahmy <youssefvictor00@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Identity: Use TimeProvider for Passkey CreatedAt
Summary of the changes (Less than 80 chars)
Use TimeProvider instead of DateTime.UtcNow in PasskeyHandler.
Description
This PR addresses the issue where passkey registration was hardcoded to use
DateTime.UtcNow. It updatesPasskeyHandlerto use the injectedTimeProviderinstead to set theCreatedAtvalue, which allows for proper unit testing of time-dependent logic.Test cases have been updated/added to verify the behavior using a fake time provider.
Fixes #66477