部署到Azure的Blazor Web App用OpenIddict认证时抛SocketException并无限循环
问题:Blazor Web App部署Azure后OpenID Connect认证陷入无限循环
我有一个采用Interactive Server Render Mode运行的Blazor Web App,以及基于OpenIddict构建的身份提供商(ID Provider)。该Blazor App配置使用Microsoft OpenIdConnectHandler,基本遵循相关安全指南。
本地运行两个应用时一切正常,但部署到Azure后,虽能成功重定向到IDP的登录页面,但认证成功后,Blazor App的/signin-oidc与IDP的授权端点之间会陷入无限循环。
查看日志发现以下异常(尽管OpenIddict似乎已成功处理令牌请求):
Category: Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler EventId: 17 SpanId: d04c97209a4248cf TraceId: f1015c14eb411718858a680b84fb7145 ParentId: 0000000000000000 RequestId: 80000052-0001-e700-b63f-84710c7967bb RequestPath: /signin-oidc Exception occurred while processing message. Exception: System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request.. ---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request. --- End of inner exception stack trace --- at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token) at System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](CancellationToken cancellationToken, Int32 estimatedSize) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](Memory`1 buffer, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.Metrics.MetricsHandler.SendAsyncWithMetrics(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts) at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.RedeemAuthorizationCodeAsync(OpenIdConnectMessage tokenEndpointRequest) at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleRemoteAuthenticateAsync()
但不确定这是实际错误还是取消请求时触发的异常。
已尝试的操作:
- 克隆Blazor Server OIDC模板仓库,修改配置使用我的IDP并部署到Azure,模板应用运行正常。
- 添加我的所有页面和组件后(配置保持不变),问题再次出现。
已知信息:
- 其他React SPA应用可正常运行
- Blazor应用本地运行正常
- 模板Blazor应用部署后正常
请问为何会出现该问题?
内容的提问来源于stack exchange,提问作者user27687530
相关产品推荐
相关产品推荐

