diff --git a/src/Microsoft.Identity.Web/WebApiServiceCollectionExtensions.cs b/src/Microsoft.Identity.Web/WebApiServiceCollectionExtensions.cs index 72afe33cb..96e68ea37 100644 --- a/src/Microsoft.Identity.Web/WebApiServiceCollectionExtensions.cs +++ b/src/Microsoft.Identity.Web/WebApiServiceCollectionExtensions.cs @@ -125,8 +125,11 @@ public static IServiceCollection AddProtectedWebApiCallsProtectedWebApi( { options.Events ??= new JwtBearerEvents(); + var onTokenValidatedHandler = options.Events.OnTokenValidated; + options.Events.OnTokenValidated = async context => { + await onTokenValidatedHandler(context).ConfigureAwait(false); context.HttpContext.StoreTokenUsedToCallWebAPI(context.SecurityToken as JwtSecurityToken); context.Success(); await Task.FromResult(0).ConfigureAwait(false);