/// <summary> /// Configures <paramref name="httpClientBuilder"/> to handle Authorization header with Access and Refresh tokens. /// </summary> /// <param name="httpClientBuilder">Target builder.</param> /// <param name="logger">Logger instance.</param> /// <param name="verbosity">Instance of verbosity bitmask. Default is <see cref="LogVerbosity.Unspecified"/>.</param> /// <returns>Modified builder.</returns> /// <exception cref="T:System.ArgumentNullException"> /// When the <paramref name="httpClientBuilder"/> parameter is <see langword="null"/> or /// the <paramref name="logger"/> parameter is <see langword="null"/>. /// </exception> public static IHttpClientBuilder WithLogger( this IHttpClientBuilder httpClientBuilder, ILogger logger, LogVerbosity verbosity = LogVerbosity.Unspecified) { if (httpClientBuilder == null) { throw new ArgumentNullException(nameof(httpClientBuilder)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } var handler = new HttpDiagnosticsHandler(logger, verbosity); return(httpClientBuilder.AddHandler(handler)); }
/// <summary> /// Configures <paramref name="httpClientBuilder"/> to handle Authorization header with Access and Refresh tokens. /// </summary> /// <param name="httpClientBuilder">Target builder.</param> /// <param name="sessionContext">Session context instance.</param> /// <returns>Modified builder.</returns> /// <exception cref="T:System.ArgumentNullException"> /// When the <paramref name="httpClientBuilder"/> parameter is <see langword="null"/> or /// the <paramref name="sessionContext"/> parameter is <see langword="null"/>. /// </exception> public static IHttpClientBuilder WithSessionContext( this IHttpClientBuilder httpClientBuilder, ISessionContext sessionContext) { if (httpClientBuilder == null) { throw new ArgumentNullException(nameof(httpClientBuilder)); } if (sessionContext == null) { throw new ArgumentNullException(nameof(sessionContext)); } var handler = new RefreshTokenHttpClientHandler( () => Task.FromResult(sessionContext.AccessToken), sessionContext.RefreshTokenAsync); return(httpClientBuilder.AddHandler(handler)); }