【发布时间】:2021-02-14 19:59:09
【问题描述】:
我有一个来自模板的简单 Blazor 应用程序。你可以在这里检查它:https://blazorfun2.azurewebsites.net/。 FetchData 页面仅适用于授权用户,但当我授权时,我得到401 Unauthorized error。在 Response 标头下显示此错误:
WWW-Authenticate: Bearer error="invalid_token", error_description="发行者 'https://blazorfun2.azurewebsites.net' 无效"
您可以使用testmail@testmail.something 和Error#2 密码进行测试。
我在本地主机上没有这个错误。
我在 Linux 上使用 Azure 应用服务,dotnet 5.0。
可以通过更改IssuerUri (source) 来解决,但我想这不是最好的选择..
//Main method in Program.cs in Client:
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.Services.AddHttpClient("BlazorPlaygroundFun.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
// Supply HttpClient instances that include access tokens when making requests to the server project
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("BlazorPlaygroundFun.ServerAPI"));
builder.Services.AddApiAuthorization();
await builder.Build().RunAsync();
//startup.cs in server project:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
services.AddControllersWithViews();
services.AddRazorPages();
这里有什么问题?谢谢!
【问题讨论】:
-
这是this 的副本吗?否则,你检查the other questions and answers on SO了吗?
-
这些问题是相关的,是的。但不适用于 blazor,也不适用于只是模板的简单应用程序。
-
您的问题解决了吗?有进展吗?
标签: c# azure azure-web-app-service blazor blazor-webassembly