Blazor WASM OIDC stating that redirect uri is undefined whatever I do(Blazor WASM OIDC声明,无论我做什么,重定向URI都是未定义的)
问题描述
所以,我遵循了Microsoft Docs和这个Medium article中的指导原则,它们建议将OIDC身份验证添加到Blazor WASM应用程序应该是轻而易举的。
我已经有一个可以正常工作的OIDC-Server(Keyloak),我已成功地将其用于多个Blazor服务器应用程序。
然后我在appsettings.json中定义了所需的属性,如下所示:
{
"OIDC": {
"Authority": "https://mykeycloakserver/auth/realms/master/",
"ClientId": "MyClientId",
"ClientSecret": "FooBarBaz-813361955dc3",
"DefaultScopes": [
"openid",
"profile",
"roles",
"offline_access"
],
"PostLogoutRedirectUri": "/",
"ResponseType": "code"
}
}
并将其添加到program.cs
builder.Services.AddOidcAuthentication(options =>
{
builder.Configuration.Bind("OIDC", options.ProviderOptions);
});
应用程序(和服务器API)启动后,我单击登录,出现以下消息:
那么无论我是定义RedirectUri到appsetting.json还是在program.cs中显式定义RedirectUri:
options.ProviderOptions.RedirectUri = "https://localhost:7066/authentication/login-callback";
它总是告诉我它是未定义的。在配置绑定后设置断点会告诉我,我的设置确实被提取了!
完整program.cs:
using MyWASM.Client;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddHttpClient("AnliegenWASM.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("MyWASM.ServerAPI"));
builder.Services.AddOidcAuthentication(options =>
{
builder.Configuration.Bind("OIDC", options.ProviderOptions);
//options.ProviderOptions.RedirectUri = "https://localhost:7066/authentication/login-callback";
});
await builder.Build().RunAsync();
那么,我错过了什么?
推荐答案
我也遇到了这个问题。仔细检查添加了JS身份验证服务的index.html页面。
我让它引用了MSAL身份验证服务:
<script src="_content/Microsoft.Authentication.WebAssembly.Msal/AuthenticationService.js"></script>
本应是:
<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
这篇关于Blazor WASM OIDC声明,无论我做什么,重定向URI都是未定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Blazor WASM OIDC声明,无论我做什么,重定向URI都是未定义的
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
