public AddAuthenticationHeaderHandler(IServiceIdentityTokenSource tokenSource, string resourceIdForMsiAuthentication) { if (!string.IsNullOrEmpty(resourceIdForMsiAuthentication)) { this.provider = new ServiceIdentityTokenProvider(tokenSource, resourceIdForMsiAuthentication); } }
/// <summary> /// Adds the management client to the service collection. /// </summary> /// <param name="services">The service collection.</param> /// <param name="configurationCallback">A callback to retrieve configuration for the client.</param> /// <returns>The service collection, for chaining.</returns> public static IServiceCollection AddUserNotificationsApiDeliveryChannelClient( this IServiceCollection services, Func <IServiceProvider, UserNotificationsApiDeliveryChannelClientConfiguration> configurationCallback) { services.AddHttpClient(nameof(UserNotificationsApiDeliveryChannelClient)) .ConfigureHttpClient((sp, client) => { UserNotificationsApiDeliveryChannelClientConfiguration config = configurationCallback(sp); client.BaseAddress = new Uri(config.BaseUri); }) .AddHttpMessageHandler(sp => { IServiceIdentityTokenSource tokenSource = sp.GetRequiredService <IServiceIdentityTokenSource>(); UserNotificationsApiDeliveryChannelClientConfiguration config = configurationCallback(sp); return(new AddAuthenticationHeaderHandler(tokenSource, config.ResourceIdForMsiAuthentication)); }); services.AddSingleton <IUserNotificationsApiDeliveryChannelClient>(sp => { IHttpClientFactory httpClientFactory = sp.GetRequiredService <IHttpClientFactory>(); return(new UserNotificationsApiDeliveryChannelClient(httpClientFactory.CreateClient(nameof(UserNotificationsApiDeliveryChannelClient)))); }); return(services); }