-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Closed
Description
Description
Updates for NRT ...
using Microsoft.AspNetCore.Components.Authorization;
namespace BlazorWebAppOidc;
public class AuthenticationStateHandler(
CircuitServicesAccessor circuitServicesAccessor)
: DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
var authStateProvider = circuitServicesAccessor.Services?
.GetRequiredService<AuthenticationStateProvider>();
var authState = authStateProvider?.GetAuthenticationStateAsync().Result;
var user = authState?.User;
if (user?.Identity is not null && user.Identity.IsAuthenticated)
{
request.Headers.Add("X-USER-IDENTITY-NAME", user.Identity.Name);
}
return await base.SendAsync(request, cancellationToken);
}
}Also ...
This section ...
... is relevant for HTTP Client, so better cross-link it into the articles where it has a bearing, such as the Call web APIs article.
Page URL
Content source URL
Document ID
85d1072a-59eb-7b01-2476-fa699ee03653
Platform Id
0bb44a31-eea5-7fdc-3d77-85dbf2f31315
Article author
Metadata
- ID: 85d1072a-59eb-7b01-2476-fa699ee03653
- PlatformId: 0bb44a31-eea5-7fdc-3d77-85dbf2f31315
- Service: aspnet-core
- Sub-service: blazor
Metadata
Metadata
Assignees
Type
Projects
Status
Done