Blazor gRPC use Windows-Authentication

21 Views Asked by At

I am using Blazor gRPC and have currently 3 projects. A .Client, a .Server and a .Shared project. I build it like this example shows: https://github.com/hakenr/BlazorGrpcWebCodeFirst

I want to have Windows-Authentication because my server uses the Windows username and interacts with a SQL DB to get user roles and so on. This is already implemented.

Now i want to activate the DefaultAuthentication for my HttClientHandler to get the user information in the service which is in the .Server project. When i currently do this:

    var httpClientHandler = new HttpClientHandler();
    httpClientHandler.UseDefaultCredentials = true;

    var httpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, httpClientHandler);

    return GrpcChannel.ForAddress(backendUrl,
        new GrpcChannelOptions { HttpHandler = httpHandler });

I get this exception:

System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Net.Http.BrowserHttpHandler.set_Credentials(ICredentials value)

Then i tried to set the RuntimeIdentifier in the project file of the .Client (.Server and .Shared already have this RuntimeIdentifier set) like this:

<PropertyGroup>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

But with this i get another error at startup because there is no dotnet.js file in my '_framework' folder.

Can i get the WindowsAuthentication work somehow else or can i do anything to create the dotnet.js file?

Thanks for all the help!

I set the UseDefaultCredentials:

    var httpClientHandler = new HttpClientHandler();
    httpClientHandler.UseDefaultCredentials = true;

    var httpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, httpClientHandler);

    return GrpcChannel.ForAddress(backendUrl,
        new GrpcChannelOptions { HttpHandler = httpHandler });

I tried to set the RuntimeIdentifier

<PropertyGroup>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
0

There are 0 best solutions below