So I needed to use per page render mode in this Blazor project, most of which are InteractiveServer. In a particular page I would like to swap between InteractiveServer and InteractiveWasm manually, at this time, then it will be InteractiveWasm.
Anyway to get and store data because of this, I use HttpClients.
The issue happens in InteractiveServer mode, if I keep the tab open for more than the access token duration, it expires and following api calls gives 401 NotAuthorized
because HttpContextAccessor.HttpContext.GetTokenAsync("access_token")
still gives the old token.
I tried to trigger the CookieAuthenticationEvents.OnValidatePrincipal
with a timer every 5 minutes. I make a javascript fetch call to a dummy api just to trigger this event, given
that the browser appends the cookies automatically.
So server side a new access token is set along with the other tokens.
I inject the httpContextAccessor at the initialization of the page, and then use it to set the bearer token to the httpClient before every call, using httpContextAccessor.HttpContext.GetTokenAsync("access_token")
but even after triggering the refresh on the server, this token is still the old one, the first that was got when page was initialized.
Is there any way to make the HttpClients works without a jwtBearer token and make them send cookies like it happens when you are in InteractiveWasm?