-
Notifications
You must be signed in to change notification settings - Fork 219
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
OnTokenValidated Invoked Twice when using the delegate form of AddIdentityWebApp #2456
Comments
It appears that this IS a bug still. ALL examples that load something from Graph OnTokenValidated do this, and it runs twice. I am to get around it by doing the following: services.Configure<MicrosoftIdentityOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
var previousOnTokenValidatedHandler = options.Events.OnTokenValidated;
options.Events.OnTokenValidated = ctx => GetGraphUserPhotoAsync(ctx, graphScopes, previousOnTokenValidatedHandler);
options.Events.OnAuthenticationFailed = OnAuthenticationFailed;
options.Events.OnRemoteFailure = OnRemoteFailure;
}); |
@jennyf19 @JoshLozensky @westin-m |
I'm seeing something similar in MIW 2.14.0 in my ASP.NET Core app where I'm trying to subscribe to OnRedirectToIdentityProvider. I'm passing an Console.WriteLine("\nConfiguring MIW options\n"); Sure enough, when I run the app locally, I see "Configuring MIW options" twice in the output. I think this is related to #1796. It looks like the configure delegate gets added first here during the call to builder.Services.Configure(openIdConnectScheme, configureMicrosoftIdentityOptions); // <---- First Configure
builder.Services.AddSingleton<IMergedOptionsStore, MergedOptionsStore>();
builder.Services.AddHttpClient(); Then, when // Ensure that configuration options for MSAL.NET, HttpContext accessor and the Token acquisition service
// (encapsulating MSAL.NET) are available through dependency injection
services.Configure(openIdConnectScheme, configureMicrosoftIdentityOptions); // <---- Second Configure Seems like there should be some sort of check to avoid the configure delegate from getting applied twice when enabling downstream token acquisition? When I apply a pattern like the one documented here for subscribing to OIDC events, it'll result in the OIDC event handlers getting invoked multiple times. |
* Fix build on .NET FW after #2480 * Fix the "The referenced project is targeted to a different framework family" warnings by changing the order of the frameworks (older to newer) as advised in https://www.primordialcode.com/blog/post/referenced-project-targeted-different-framework-family * Fixes #2456 * Addressing comments
Microsoft.Identity.Web Library
Microsoft.Identity.Web
Microsoft.Identity.Web version
2.13.4
Web app
Sign-in users and call web APIs
Web API
Protected web APIs (validating scopes/roles)
Token cache serialization
In-memory caches
Description
Based upon multiple examples on how to call MS Graph after signing in, I would hope that OnTokenValidated is only called once. However, it is called twice.
Reproduction steps
See code.
Error message
No response
Id Web logs
No response
Relevant code snippets
Regression
No response
Expected behavior
OnTokenValidated should only be invoked once.
The text was updated successfully, but these errors were encountered: