Skip to content

Invalidate Cached WASM Auth Token on Authentication State Change #36358

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

Merged
merged 3 commits into from
Sep 10, 2021

Conversation

TanayParikh
Copy link
Contributor

Fixes: #35888

This should work. I'm unable to validate it as for some reason the AuthenticationStateChanged event is never invoked (should be invoked on sign in/out). I'm assuming this is some issue with the debugger. I've validated that the event does in fact attach (line 44).

@TanayParikh TanayParikh requested a review from a team as a code owner September 10, 2021 01:43
@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Sep 10, 2021
@@ -16,10 +13,11 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// Access tokens will only be added when the request URI is within one of the base addresses configured using
/// <see cref="ConfigureHandler(IEnumerable{string}, IEnumerable{string}, string)"/>.
/// </summary>
public class AuthorizationMessageHandler : DelegatingHandler
public class AuthorizationMessageHandler : DelegatingHandler, IDisposable
Copy link
Contributor

Choose a reason for hiding this comment

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

HttpMessageHandler from which DelegatingHandler inherits already implements IDisposable so you could just override the existing protected virtual void Dispose(bool disposing) method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I'd originally done prior to e2351d3. The issue with that approach is it requires adding a new public API, which at this stage of the release is a bit tougher.

{
authStateProvider.AuthenticationStateChanged -= _authenticationStateChangedHandler;
}
Dispose(disposing: true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Defaulted this to true.

@TanayParikh TanayParikh merged commit 883c7fc into main Sep 10, 2021
@TanayParikh TanayParikh deleted the taparik/handleStaleAuthToken branch September 10, 2021 18:22
@ghost ghost added this to the 7.0-preview1 milestone Sep 10, 2021
@TanayParikh
Copy link
Contributor Author

/backport to release/6.0

@github-actions
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blazor WASM AuthorizationMessageHandler caches AccessToken even after user has changed
3 participants