Open grabthefish opened 2 months ago
just found this exception in the event viewer: The provided identity of type 'System.Security.Claims.ClaimsIdentity' is marked IsAuthenticated = true but does not have a value for Name. By default, the antiforgery system requires that all authenticated identities have a unique Name.
It's weird that it's complaning about the Name
claim while adding any random claim (even new Claim("foo", "bar")
as in my sample) fixes the issue
Category: Microsoft.AspNetCore.Server.Kestrel
EventId: 13
SpanId: 80dc61ccbd61c080
TraceId: a481fcb2a0cb59cf16ca5df81c8086a1
ParentId: 0000000000000000
ConnectionId: 0HN6EMPK3TD3F
RequestId: 0HN6EMPK3TD3F:00000033
RequestPath: /
Connection id "0HN6EMPK3TD3F", Request id "0HN6EMPK3TD3F:00000033": An unhandled exception was thrown by the application.
Exception:
System.ObjectDisposedException: The response has been aborted due to an unhandled application exception.
---> System.InvalidOperationException: The provided identity of type 'System.Security.Claims.ClaimsIdentity' is marked IsAuthenticated = true but does not have a value for Name. By default, the antiforgery system requires that all authenticated identities have a unique Name. If it is not possible to provide a unique Name for this identity, consider extending IAntiforgeryAdditionalDataProvider by overriding the DefaultAntiforgeryAdditionalDataProvider or a custom type that can provide some form of unique identifier for the current user.
at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenGenerator.GenerateRequestToken(HttpContext httpContext, AntiforgeryToken cookieToken)
at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetTokensInternal(HttpContext httpContext)
at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetAndStoreTokens(HttpContext httpContext)
at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.<>c__DisplayClass4_0.<RenderComponentCore>b__0()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<FireOnStarting>g__ProcessEvents|241_0(HttpProtocol protocol, Stack`1 events)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.FirstWriteAsyncInternal(ReadOnlyMemory`1 data, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.WritePipeAsync(ReadOnlyMemory`1 data, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.WriteAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Watch.BrowserRefresh.WebSocketScriptInjection.TryInjectLiveReloadScriptAsync(Stream baseStream, ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Watch.BrowserRefresh.ResponseStreamWrapper.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)
at Microsoft.WebTools.BrowserLink.Net.WebSocketScriptInjection.TryInjectBrowserLinkScriptAsync(Stream baseStream, ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)
at Microsoft.WebTools.BrowserLink.Net.ResponseStreamWrapper.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)
at Microsoft.AspNetCore.WebUtilities.HttpResponseStreamWriter.FlushInternalAsync(Boolean flushEncoder)
at Microsoft.AspNetCore.Components.Endpoints.Rendering.BufferedTextWriter.FlushAsyncCore(Task priorTask)
at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<<InvokeAsync>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
at Microsoft.WebTools.BrowserLink.Net.BrowserLinkMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
Is there an existing issue for this?
Describe the bug
signing in on the HttpContext with CookieAuthentication and an ClaimsPrincipal without claims will stop any page from rendering
Expected Behavior
The pages to still be rendering correctly
Steps To Reproduce
minimal repo https://github.com/grabthefish/ClaimTest/ on this specific commit you can see the changes made https://github.com/grabthefish/ClaimTest/commit/846e11511ffad814bbcc67ad2174a0bc7d7c7eac
Exceptions (if any)
No response
.NET Version
8.0.302
Anything else?