我有一些 .NET Core 托管的 Web 程序集项目,它在外部公司服务器上使用 OIDC 身份验证,配置为:
builder.Services.AddOidcAuthentication(opt =>
{
opt.ProviderOptions.Authority = "https://xx.xx.pl/auth/realms/xx";
opt.ProviderOptions.ClientId = "xxxx";
opt.ProviderOptions.DefaultScopes.Add("email");
opt.ProviderOptions.ResponseType = "code";
});
我想要这样的:
在 .NET 8 中,我不使用
CascadingAuthenticationState
组件,所以如果我添加:
builder.Services.AddCascadingAuthenticationState();
没有任何改变/重定向,因为它应该/没有任何中断。
但是当我删除
<CascadingAuthenticationState>
组件时,当我运行时,我看到未授权 - 好吧
按照应有的方式重定向到外部登录页面,我可以登录,然后返回“我的页面”
我看到“身份验证完成登录...”,但它没有重定向到上一页,而是失败并显示:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Collection was modified; enumeration operation may not execute.
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List`1.Enumerator[[Microsoft.AspNetCore.Components.Rendering.ComponentState, Microsoft.AspNetCore.Components, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNextRare()
at System.Collections.Generic.List`1.Enumerator[[Microsoft.AspNetCore.Components.Rendering.ComponentState, Microsoft.AspNetCore.Components, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
at Microsoft.AspNetCore.Components.CascadingValueSource`1.<>c__DisplayClass10_0[[System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Components.Authorization.AuthenticationState, Microsoft.AspNetCore.Components.Authorization, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<NotifyChangedAsync>b__0()
at Microsoft.AspNetCore.Components.WebAssembly.Rendering.NullDispatcher.InvokeAsync(Action workItem)
at Microsoft.AspNetCore.Components.CascadingValueSource`1[[System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Components.Authorization.AuthenticationState, Microsoft.AspNetCore.Components.Authorization, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].NotifyChangedAsync()
at Microsoft.AspNetCore.Components.CascadingValueSource`1[[System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Components.Authorization.AuthenticationState, Microsoft.AspNetCore.Components.Authorization, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].NotifyChangedAsync(Task`1 newValue)
at Microsoft.Extensions.DependencyInjection.CascadingAuthenticationStateServiceCollectionExtensions.AuthenticationStateCascadingValueSource.HandleAuthenticationStateChanged(Task`1 newAuthStateTask)
at Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider.NotifyAuthenticationStateChanged(Task`1 task)
at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService`3[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteUserAccount, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.WebAssembly.Authentication.OidcProviderOptions, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].UpdateUser(Task`1 task)
at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService`3.<UpdateUserOnSuccess>d__30[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteUserAccount, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.WebAssembly.Authentication.OidcProviderOptions, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService`3.<CompleteSignInAsync>d__21[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteUserAccount, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.WebAssembly.Authentication.OidcProviderOptions, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorViewCore`1.<ProcessLogInCallback>d__86[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorViewCore`1.<OnParametersSetAsync>d__84[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
添加
builder.Services.AddOptions();
builder.Services.AddAuthorizationCore();
我做错了什么?
感谢和问候
我有完全相同的问题。 找到解决办法了吗??