Xamarin.forms Asp.net核心授权仅对xamarin表单应用程序失败

Xamarin.forms Asp.net核心授权仅对xamarin表单应用程序失败,xamarin.forms,jwt,asp.net-core-webapi,dotnet-httpclient,blazor-webassembly,Xamarin.forms,Jwt,Asp.net Core Webapi,Dotnet Httpclient,Blazor Webassembly,我开发了一个简单的应用程序来实践。 组合是ASP.NET内核和JWT令牌 在我的asp.net core 3.1服务器上,我有以下DI代码: services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultC

我开发了一个简单的应用程序来实践。 组合是ASP.NET内核和JWT令牌

在我的asp.net core 3.1服务器上,我有以下DI代码:

services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
                {
                    options.TokenValidationParameters = new TokenValidationParameters
                    {
                        ValidateIssuer = true,
                        ValidateAudience = true,
                        ValidateLifetime = true,
                        ValidateIssuerSigningKey = true,
                        ValidIssuer = configuration["jwt:Issuer"],
                        ValidAudience = configuration["jwt:Audience"],
                        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["jwt:Key"]))
                    };
                });
我可以轻松地与Postman或BlazorApp连接以生成令牌并使用该令牌使用其他端点。 在Blazor上,我只需要插入一个DefaultHeader:

\u httpClient.DefaultRequestHeaders.Authorization=新的AuthenticationHeaderValue(“承载者”,令牌)

现在,我正试图用Xamarin表单应用程序做同样的事情。 我试图在默认头上使用生成的令牌,但得到了未经授权的响应

要调试Xamarin Forms应用程序,我必须将localhost端点名称更改为127.0.0.1(以便仿真器可以访问我机器上的asp.net API)

我尝试将JWT令牌的颁发者改为127.0.0.1而不是localhost,但没有成功

有人能帮忙吗

提前谢谢。

我两天后收到了

我的asp.net核心api使用的是HttpsRedirect,我的Xamarin Mobile没有指向HTTPS端口

我不知道为什么,因为postman和blazor同时使用两个端点(HTTP和https端口),但Xamarin从我使用https端点开始工作

现在没事了。 无论如何谢谢你

试试这个工具