Microsoft による Blazor WebAssembly スタンドアロン アプリのチュートリアルに従いました。Identity Server 4 とログイン用の UI がインストールされているなどを使用しており、よく知られているページを表示できました。blazor アプリからの標準的なログインに必要なものはすべて揃っていると思いましたが、Identity Server のログイン ページにアクセスできませんでした。代わりに、ログイン リンクをクリックすると、Blazor アプリから次のエラー メッセージが返されます。
ログイン中にエラーが発生しました:「無効な応答コンテンツ タイプ: text/html、URL から: https:login.microsoftonline.com/.well-known/openid-configuration」
なぜこれが起こっているのかはわかりません。また、URL が microsoftonline.com に向けられている理由もわかりません。ここで明らかなステップが欠けているように感じます。私は何が欠けていますか?
Blazor launchSettings:
{
"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();
}
Identity Server の起動設定:
{
"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
}
};