HttpClient not attaching token

Lex K 31 Reputation points
2021-06-23T20:08:27.907+00:00

I'm working on a Blazor app, where I want to use a separate service to do all the API calls. However, this service, even though it has the httpClient in the constructor doesn't seem to have the token passed in.

My Program.cs code:

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });  
  
 builder.Services.AddHttpClient<IUserAdminService, UserAdminService>  
                ("userClient", client => client.BaseAddress = new Uri("https://localhost:5011")).AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();  
  
builder.Services.AddOidcAuthentication(options =>  
            {  
                builder.Configuration.Bind("Auth0", options.ProviderOptions);  
                options.ProviderOptions.ResponseType = "code";  
          options.ProviderOptions.AdditionalProviderParameters.Add("audience", "[audience]");  
            });  

108745-image.png

When I log in, I can see a call being done to get the token, but for some reason its not on the HTTP client in the services.

I'm currently using the latest preview of blazor dotnet 6

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,371 questions
{count} votes