我按照微软的 Blazor WebAssembly 独立应用程序教程进行操作。我正在使用 Identity Server 4 以及为登录等而安装的 UI,并且能够查看众所周知的页面。我假设我已经准备好从 blazor 应用程序进行标准登录的一切准备就绪,但我从未进入 Identity Server 的登录页面。相反,当我点击登录链接时,Blazor 应用程序会返回此错误消息:
尝试登录时出错:“无效响应内容类型:文本/html,来自 URL:https:login.microsoftonline.com/.well-known/openid-configuration”
我不确定为什么会发生这种情况,而且我不知道为什么 url 指向 microsoftonline.com。我觉得我在这里错过了一个明显的步骤。我错过了什么?
Blazor 启动设置:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59723",
"sslPort": 44398
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ClientBlazor": {
"commandName": "Project",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5003",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Blazor 应用设置:
{
"Local": {
"Authority": "https://localhost:5001",
"ClientId": "BlazorClient",
"DefaultScopes": [
"openid",
"profile"
],
"PostLogoutRedirectUri": "/",
"ResponseType": "code"
}
}
Blazor 主要方法:
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddOidcAuthentication(options =>
{
// Configure your authentication provider options here.
// For more information, see https://aka.ms/blazor-standalone-auth
builder.Configuration.Bind("Local", options.ProviderOptions);
});
await builder.Build().RunAsync();
}
身份服务器启动设置:
{
"profiles": {
"SelfHost": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001"
}
}
}
身份服务器配置:
public static IEnumerable<Client> Clients =>
new List<Client>
{
// SPA client using code flow + pkce
new Client
{
ClientId = "BlazorClient",
ClientName = "Blazor Client",
ClientUri = "https://loclhost:5003/",
AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
RequireClientSecret = false,
RedirectUris =
{
"https://localhost:5003/authentication/login-callback"
},
PostLogoutRedirectUris = { "http://localhost:5003/" },
AllowedCorsOrigins = { "http://localhost:5003" },
AllowedScopes = { "openid", "profile" },
Enabled = true
}
};