Skip to content

Identity: Use TimeProvider for Passkey CreatedAt#66569

Open
Vladik29w wants to merge 3 commits intodotnet:mainfrom
Vladik29w:fix-passkey-timeprovider
Open

Identity: Use TimeProvider for Passkey CreatedAt#66569
Vladik29w wants to merge 3 commits intodotnet:mainfrom
Vladik29w:fix-passkey-timeprovider

Conversation

@Vladik29w
Copy link
Copy Markdown

Identity: Use TimeProvider for Passkey CreatedAt

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

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 updates PasskeyHandler to use the injected TimeProvider instead to set the CreatedAt value, 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

Copilot AI review requested due to automatic review settings May 2, 2026 17:54
@github-actions github-actions Bot added the area-identity Includes: Identity and providers label May 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PasskeyHandler to obtain the current UTC time via TimeProvider resolved from request services (with fallback).
  • Add/adjust unit test coverage to validate CreatedAt is sourced from a fake TimeProvider.

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 thread src/Identity/test/Identity.Test/Passkeys/PasskeyHandlerAttestationTest.cs Outdated
Comment on lines +682 to +683
private static DateTime GetUtcNow(HttpContext httpContext)
=> (httpContext.RequestServices.GetService<TimeProvider>() ?? TimeProvider.System).GetUtcNow().UtcDateTime;
@Vladik29w
Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 2, 2026
@dotnet-policy-service
Copy link
Copy Markdown
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>
Comment thread src/Identity/Core/src/PasskeyHandler.cs
Comment thread src/Identity/Core/src/PasskeyHandler.cs
Co-authored-by: Youssef Fahmy <youssefvictor00@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-identity Includes: Identity and providers community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passkey CreatedAt ignores TimeProvider

3 participants