使用带有Windows身份验证的Blazor客户端使用Web API [英] Using Blazor Client-Side consuming Web API with Windows Authentication

查看:103
本文介绍了使用带有Windows身份验证的Blazor客户端使用Web API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我有一个与Angular Client一起运行的应用程序,使用了Windows身份验证的Web API.

Currently I've got an application running with and angular client, consuming a Web API with Windows Authentication.

现在,我正在考虑用Blazor(客户端)替换此前端,但是在身份验证方面,我面临一些挑战.

Now I'm looking into replacing this front end with Blazor (client-side), however I'm facing some challenges when it comes to authentication.

在角度中,我只是将withCredentials设置为true以便提交所需的信息.

In angular I just set withCredentials to true in order to submit the required information.

下面的代码可以使用Blazor服务器端正常工作,但是由于我想使用Blazor客户端,因此这不是一种选择,对我没有太大帮助.

The code below works as intended using Blazor server-side, but since I want to use Blazor client-side it's not an option and doesn't help me much.


    IEnumerable<SearchView> searchResults;
    int NumberOfItems;

    protected override async Task OnInitAsync()
    {
        using (var client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true }))
        {
            var result = await client.GetJsonAsync<Response<SearchView>>("http://localhost:80/search");
            NumberOfItems = result.TotalItemCount;
            searchResults = result.Items;
        }
    }
}

上面的代码抛出"PlatformNotsupportedException".

The above code throws an "PlatformNotsupportedException".

WASM:System.PlatformNotSupportedException:当前平台不支持System.Net.Http.HttpClientHandler.WASM:位于System.Net.Http.HttpClientHandler.set_UseDefaultCredentials(System.Boolean值)的< 0x1d63160 + 0x0000c>在< 4399d2484a2a46159ade8054ed94c78e>:0

WASM: System.PlatformNotSupportedException: System.Net.Http.HttpClientHandler is not supported on the current platform. WASM: at System.Net.Http.HttpClientHandler.set_UseDefaultCredentials (System.Boolean value) <0x1d63160 + 0x0000c> in <4399d2484a2a46159ade8054ed94c78e>:0

很明显,使用Blazor客户端不支持所提供的代码,但是如果有任何其他方法可以实现我想要的功能,则将感谢任何指针和帮助.

Clearly the code provided is not supported using Blazor client-side, but if there are any alternative ways to achieve what I want to, any pointers and help would be appreciated.

推荐答案

(尚无法).Blazor客户端在不支持Windows身份验证的.net框架的Mono运行时上运行.

This is not (yet) possible. Blazor client-side runs on the Mono runtime of the .net framework which does not support Windows Authentication.

您最好的选择是实施基于令牌的身份验证(例如,JWT)并使用ADFS.

Your best option is to implement a token based auth (JWT for instance) and use ADFS.

这篇关于使用带有Windows身份验证的Blazor客户端使用Web API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆