Skip to content

Identity: Use TimeProvider for Passkey CreatedAt - #66569

Merged
Youssef1313 merged 7 commits into
dotnet:mainfrom
Vladik29w:fix-passkey-timeprovider
Aug 19, 2026
Merged

Youssef1313 merged 7 commits into
dotnet:mainfrom
Vladik29w:fix-passkey-timeprovider

Conversation

@Vladik29w

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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/Core/src/PasskeyHandler.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
Contributor 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 <[email protected]>
Comment thread src/Identity/Core/src/PasskeyHandler.cs Resolved
Comment thread src/Identity/Core/src/PasskeyHandler.cs Resolved
@Vladik29w

Copy link
Copy Markdown
Contributor Author

hi @Youssef1313, I fixed formating a while ago, so i just wondering why my PR havent merged yet. Do i have to do something else ?

@Youssef1313
Youssef1313 requested a review from javiercn June 24, 2026 03:20

@Youssef1313 Youssef1313 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@javiercn for a second look.

Comment thread src/Identity/Core/src/PasskeyHandler.cs Resolved
@Youssef1313
Youssef1313 merged commit b006afd into dotnet:main Aug 19, 2026
25 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Aug 20, 2026
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

4 participants