You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A client asked me to upgrade a project started on the .NET 7 Blazor Wasm Fullstack Hero starter / template.
An upgrade to .NET 8+ & to convert it to a Blazor Server app.
Converting to a Blazor Server app or a Blazor Web App was troublesome due to its dependency on Microsoft.AspNetCore.Components.WebAssembly.Authentication and a major issue in the DelegatingHandler: JwtAuthenticationHeaderHandler.
On line 67 in the JwtAuthenticationService,cs, tokens are correctly stored into the local storage. Using the JsRuntime is no problem.
However, line 70 triggers an HTTP call: var permissions = await _client.GetUserPermissionsAsync(); which in turn activates the DelegatingHandler: JwtAuthenticationHeaderHandler.
At this point, the DelegatingHandler attemtps to get an access token: _tokenProviderAccessor.TokenProvider.GetAccessTokenAsync() -> tokenProvider.RequestAccessToken(). Which crashes on a "statically rendered ... JsRuntime cannot be accessed ..." for some reason.
So, I tried filling properties on JwtAuthenticationService with those tokens and try to use those in the DelegatingHandler.
Still NULL. Which makes me wonder if there's a scoping issue or rather Blazor Server's multi-threading nature or ... I'm just guessing.
Anyway, my ugly workaround is to register an extra Singleton with properties for the tokens and the permissions.
I simply inject that Singleton into the Delegating handler and that seems to work.
I tried using the HttpContextAccessor as well but no cigar.
It would be great if you guys could drop the dependency on Microsoft.AspNetCore.Components.WebAssembly.Authentication and resolve the above scoping issue.
The text was updated successfully, but these errors were encountered:
Hi,
A client asked me to upgrade a project started on the .NET 7 Blazor Wasm Fullstack Hero starter / template.
An upgrade to .NET 8+ & to convert it to a Blazor Server app.
Converting to a Blazor Server app or a Blazor Web App was troublesome due to its dependency on
Microsoft.AspNetCore.Components.WebAssembly.Authentication
and a major issue in the DelegatingHandler:JwtAuthenticationHeaderHandler
.On line 67 in the
JwtAuthenticationService,cs
, tokens are correctly stored into the local storage. Using the JsRuntime is no problem.However, line 70 triggers an HTTP call:
var permissions = await _client.GetUserPermissionsAsync();
which in turn activates the DelegatingHandler:JwtAuthenticationHeaderHandler
.At this point, the DelegatingHandler attemtps to get an access token:
_tokenProviderAccessor.TokenProvider.GetAccessTokenAsync()
->tokenProvider.RequestAccessToken()
. Which crashes on a "statically rendered ... JsRuntime cannot be accessed ..." for some reason.So, I tried filling properties on
JwtAuthenticationService
with those tokens and try to use those in the DelegatingHandler.Still NULL. Which makes me wonder if there's a scoping issue or rather Blazor Server's multi-threading nature or ... I'm just guessing.
Anyway, my ugly workaround is to register an extra Singleton with properties for the tokens and the permissions.
I simply inject that Singleton into the Delegating handler and that seems to work.
I tried using the HttpContextAccessor as well but no cigar.
It would be great if you guys could drop the dependency on
Microsoft.AspNetCore.Components.WebAssembly.Authentication
and resolve the above scoping issue.The text was updated successfully, but these errors were encountered: