Open ggomarighetti opened 10 months ago
@MackinnonBuck Could this be because CreateInboundActivityHandler is not being called when it should be? @rsandbach pointed out that #51934 and #52390 could be related.
Thanks for contacting us.
We're moving this issue to the .NET 9 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
@ggomarighetti, the problem may have been caused by #51934, which is getting addressed in the February servicing release for .NET 8. Would you be able to try the new release in February and see if it resolves the issue?
@MackinnonBuck no problem, as soon as the new version is available, I will run the test again and report the news in the issue. Thank you very much!
Similarly, if this change allows arbitrary assemblies to once again access the user identity in Blazor I'll let you know.
I don't know how we're supposed to build real apps without access to the current user's roles, claims, etc.
@MackinnonBuck I have tested with the new versions and the issue has not been solved.
By looking at this, I managed to get the right DI scope from within my DelegatingHandler
I'm basically putting the access token in a scoped service from within the CircuitHandler.OnConnectionUpAsync
method, then I use the CircuitServicesAccessor
injected in the DelegatingHandler
in order to fetch the right DI scope.
See also this for an example with AuthenticationStateProvider
Currently I no longer use Blazor for development.
For those who read this message later, the only way to apply authentication and authorization correctly for an application with Blazor is to use a BFF pattern.
Investigate the libraries or tutorials that exist at the time you read this, but, in principle, it is based on developing the Blazor application in client mode (Web Assembly) and securing everything with an ASP.NET REST API on top.
This way you can connect the API to your authentication provider (in my case it was with Auth0) and be able to refresh the access token (in my case it was short lifetime) in an effective and efficient way.
Honorable mention to @rockfordlhotka's comment, I don't know how they expect real applications to be developed with a framework in this state.
I have currently migrated the project to TypeScript with NextJS. If necessary I can keep the issue open until the problem is solved, another way to do it is found or a library is developed that can solve it.
Regards!
The only thing that has worked for me is using the pre-8.0 way described here.
Having to make every component that performs API calls inherit from the custom component base obviously isn't great and even then it sometimes just breaks for reasons I don't understand (even though I am able to work around it).
The new approach added to 8.0 simply does not work, services are always null. Also, CreateInboundActivityHandler never gets called.
Is there an existing issue for this?
Describe the bug
I try to access AuthenticationStateProvider from a DelegatingHandler which intercepts requests from an HttpClient, following the official documentation guidelines:
But I get errors when implementing it in a completely new Blazor project (Server Side) in .NET 8 SDK.
Expected Behavior
I am looking to access the AuthenticationStateProvider from the DelegateHandler.
Steps To Reproduce
Program.cs
SecurityServiceAccessor.cs
SecurityCircuitHandler.cs
SecurityHandler.cs
Home.razor
Exceptions (if any)
.NET Version
8.0.100
Anything else?
SDK DE .NET: Version: 8.0.100
Commit: 57efcf1350 Workload version: 8.0.100-manifests.6a1e483a
Entorno de tiempo de ejecución:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.100\
Cargas de trabajo de .NET instaladas:
Workload version: 8.0.100-manifests.6a1e483a [ios]
Origen de la instalación: VS 17.8.34316.72
Versión del manifiesto: 17.0.8478/8.0.100
Ruta de acceso del manifiesto: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.0.8478\WorkloadManifest.json Tipo de instalación: Msi
[maui-windows]
Origen de la instalación: VS 17.8.34316.72 Versión del manifiesto: 8.0.3/8.0.100 Ruta de acceso del manifiesto: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.3\WorkloadManifest.json Tipo de instalación: Msi
[android] Origen de la instalación: VS 17.8.34316.72 Versión del manifiesto: 34.0.43/8.0.100 Ruta de acceso del manifiesto: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.43\WorkloadManifest.json Tipo de instalación: Msi
[maccatalyst] Origen de la instalación: VS 17.8.34316.72 Versión del manifiesto: 17.0.8478/8.0.100 Ruta de acceso del manifiesto: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.0.8478\WorkloadManifest.json Tipo de instalación: Msi
Host: Version: 8.0.0 Architecture: x64 Commit: 5535e31a71
.NET SDKs installed: 6.0.403 [C:\Program Files\dotnet\sdk] 8.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables: Not set
global.json file: C:\Users\ggomarighetti\source\repos\minerva-front\global.json
Learn more: https://aka.ms/dotnet/info
Download .NET: https://aka.ms/dotnet/download