I have a simple Blazor app from template. You can inspect it here: https://blazorfun2.azurewebsites.net/ . FetchData page is only for authorized users, but when I authorize I get 401 Unauthorized error
. Under the Response header it shows this error:
WWW-Authenticate: Bearer error="invalid_token", error_description="The issuer 'https://blazorfun2.azurewebsites.net' is invalid"
You can test that with testmail@testmail.something
and Error#2
password.
I don't have this error on local host.
I am using Azure app service, dotnet 5.0 on Linux.
It is solvable by changing IssuerUri
(source), but I guess it's not the best option..
//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();
What is wrong here? Thank you!