grpc web channel setup for authenticated request in Blazer with dotnet 8 authentication

73 Views Asked by At

I'm trying to upgrade a blazor 7 Wasm project to use dotnet 8 and the new authentication mechanism and I've hit a problem with creating the gRpc channel.

In dotnet 7 with microsoft.identity this was the channel setup (which worked):

var baseAddressMessageHandler = 
sp.GetRequiredService<BaseAddressAuthorizationMessageHandler>();
baseAddressMessageHandler.InnerHandler = new HttpClientHandler();
var grpcWebHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, baseAddressMessageHandler);
var channel = GrpcChannel.ForAddress(builder.HostEnvironment.BaseAddress, new 
GrpcChannelOptions { HttpHandler = grpcWebHandler });

However - contrary to what the documetnation suggests - BaseAddressAuthorizationMessageHandler is not registered by the framework and there is no IAccessTokenProvider available for me to register it myself.

I've tried all the bits that I could think of from here: https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/additional-scenarios?view=aspnetcore-8.0

But I haven't managed to work out how to authenticate with gRpc yet. I'm not sure if I'm missing something or if I'm trying to do something that can't be done, but any help appreciated!

0

There are 0 best solutions below