question

LexKruijsse-6305 avatar image
0 Votes"
LexKruijsse-6305 asked AgaveJoe commented

HttpClient not attaching token

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

dotnet-aspnet-core-blazor
image.png (12.3 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm not sure if your app is hosted or not but the docs explain, Access tokens are only added when the request URI is within the app's base URI. I use the following pattern from the docs and configure a AuthorizationMessageHandler. I think you are interested in the typed client.


0 Votes 0 ·

0 Answers