first commit -push
This commit is contained in:
27
RobotNet.WebApp/Helpers/ServiceCollectionExtensions.cs
Normal file
27
RobotNet.WebApp/Helpers/ServiceCollectionExtensions.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace RobotNet.WebApp.Helpers;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IHttpClientBuilder AddAuthorizationHttpClient(this IServiceCollection services, string name, string baseAddress)
|
||||
{
|
||||
return services.AddHttpClient(name, client =>
|
||||
{
|
||||
client.BaseAddress = new Uri(baseAddress);
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
})
|
||||
.AddHttpMessageHandler(sp =>
|
||||
{
|
||||
var tokenProvider = sp.GetRequiredService<IAccessTokenProvider>();
|
||||
var navigation = sp.GetRequiredService<NavigationManager>();
|
||||
var messageHandle = new AuthorizationMessageHandler(tokenProvider, navigation);
|
||||
|
||||
messageHandle.ConfigureHandler([baseAddress]);
|
||||
return messageHandle;
|
||||
})
|
||||
.RemoveAllLoggers();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user