-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add missing TimeProvider registration #53946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add missing TimeProvider registration #53946
Conversation
Looks like the existing tests live in the aspnetcore/src/Identity/test/Identity.Test/IdentityBuilderTest.cs Lines 175 to 197 in c52a7ab
|
Thanks for pointing me in the right direction. I've added a new test method since Also, on a side note, I've noticed in the test class a rather often usage of |
/azp run |
Commenter does not have sufficient privileges for PR 53946 in repo dotnet/aspnetcore |
@martincostello Anything more I should do? |
If you close and re-open the PR, that will make the CI re-run. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the bug report and the PR @Prologh!
Ideally, the SecurityStamValidator
shouldn't need a TimeProvider
registered with DI. It just needs to use it if it's available. The typical way to do this is to add a constructor to the service that doesn't take a TimeProvider
(or makes it optional) and add logic to fall back to TimeProvider.System
if it's not provided. This is basically what SecurityStampValidator
does.
Can we do something like the following for PostConfigureSecurityStampValidatorOptions
?
public PostConfigureSecurityStampValidatorOptions(TimeProvider? timeProvider = null)
{
// We could assign this to "timeProvider ?? TimeProvider.System", but
// SecurityStampValidator already has system clock fallback logic.
TimeProvider = timeProvider;
}
private TimeProvider? TimeProvider { get; }
It looks like we also need the same fix in AddIdentity<TUser, TRole>
which has its own copy of PostConfigureSecurityStampValidatorOptions
does not call AddSignInManager
or AddSignInManagerDeps
.
We'll have to remove Assert.NotNull(provider.GetService<TimeProvider>());
from the tests, but everything else should still work.
Sure. I made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Add missing TimeProvider registration
Summary of the changes (Less than 80 chars)
Add missing
TimeProvider
registrationAddSignInManager()
method onIdentityBuilder
adds dependencies that useTimeProvider
but does not register an implementation for it within service collection. That results inInvalidOperationException
being thrown on application startup for invalid service descriptor, because of missingTimeProvider
implementation.Fixes #53938
I haven't been able to locate unit tests that would cover specifically that identity builder methods. Any guidance for that would be welcomed if there is a need to add test coverage for the change.