-
Notifications
You must be signed in to change notification settings - Fork 215
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
2.15.1 must wait all OnTokenValidated delegates to completion #2513
Comments
@recumbented : do you think it would be better to use delegate chaining? |
@jmprieur Therefore OnTokenValidated exposes HttpContext, all invocations should be run in HttpContext scope.
And invoke at first below resolves issue #2508. Lines 168 to 183 in 0a212c4
|
@westin-m : in 2.15.1, this PR introduced an undesirable behavioral change which I had not though of. What to do: // Handling the token validated to get the client_info for cases where tenantId is not present (example: B2C)
var onTokenValidatedHandler = options.Events.OnTokenValidated;
options.Events.OnTokenValidated = async context =>
{
string? clientInfo = context!.ProtocolMessage?.GetParameter(ClaimConstants.ClientInfo);
if (!string.IsNullOrEmpty(clientInfo))
{
ClientInfo? clientInfoFromServer = ClientInfo.CreateFromJson(clientInfo);
if (clientInfoFromServer != null && clientInfoFromServer.UniqueTenantIdentifier != null && clientInfoFromServer.UniqueObjectIdentifier != null)
{
context!.Principal!.Identities.FirstOrDefault()?.AddClaim(new Claim(ClaimConstants.UniqueTenantIdentifier, clientInfoFromServer.UniqueTenantIdentifier));
context!.Principal!.Identities.FirstOrDefault()?.AddClaim(new Claim(ClaimConstants.UniqueObjectIdentifier, clientInfoFromServer.UniqueObjectIdentifier));
}
}
await onTokenValidatedHandler(context).ConfigureAwait(false);
}; cc: @jennyf19 to prioritize |
@recumbented A fix for this is proposed in #2524. If you can, please try it for yourself and let us know the results. |
@westin-m Thanks. I tested and confirmed it works as expected. |
Microsoft.Identity.Web v2.15.2 contains a fix for this issue. |
Microsoft.Identity.Web Library
Microsoft.Identity.Web
Microsoft.Identity.Web version
2.15.1
Web app
Sign-in users
Web API
Protected web APIs (validating tokens)
Token cache serialization
In-memory caches
Description
Related to #2508
Since 2.15.1, OnTokenValidated is used as MulticastDelegate.
So
await _onTokenValidated(context);
will not wait it's invocations.This causes unexpected behavior in users's OnTokenValidated invocation.
It's desired to wait all invocations like
Reproduction steps
If you use scoped services from DI in OnTokenValidated,
async method invocation may throw ObjectDisposedException.
Error message
No response
Id Web logs
No response
Relevant code snippets
The text was updated successfully, but these errors were encountered: