• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / HashGate / 17882037893

20 Sep 2025 04:09PM UTC coverage: 79.529%. First build
17882037893

push

github

pwelter34
Add .NET Standard 2.0 support and improve compatibility

118 of 182 branches covered (64.84%)

Branch coverage included in aggregate %.

11 of 19 new or added lines in 3 files covered. (57.89%)

321 of 370 relevant lines covered (86.76%)

12.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/HashGate.HttpClient/DependencyInjectionExtensions.cs
1
using Microsoft.Extensions.DependencyInjection;
2

3
namespace HashGate.HttpClient;
4

5
/// <summary>
6
/// Provides extension methods for configuring HMAC authentication services in the dependency injection container.
7
/// </summary>
8
public static class DependencyInjectionExtensions
9
{
10
    /// <summary>
11
    /// Adds HMAC authentication services to the specified <see cref="IServiceCollection"/>.
12
    /// This method configures the required services for HTTP client-side HMAC authentication,
13
    /// including options binding from configuration and the HTTP message handler.
14
    /// </summary>
15
    /// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
16
    /// <param name="configure">
17
    /// An optional action to configure the <see cref="HmacAuthenticationOptions"/>.
18
    /// This allows for programmatic configuration in addition to configuration binding.
19
    /// If provided, this configuration will be applied after the configuration binding.
20
    /// </param>
21
    /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
22
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="services"/> is <c>null</c>.</exception>
23
    /// <remarks>
24
    /// <para>
25
    /// This method performs the following registrations:
26
    /// </para>
27
    /// <list type="bullet">
28
    /// <item><description>Configures <see cref="HmacAuthenticationOptions"/> with automatic binding to the "HmacAuthentication" configuration section</description></item>
29
    /// <item><description>Enables validation of options on application startup</description></item>
30
    /// <item><description>Registers the <see cref="HmacAuthenticationHttpHandler"/> as a transient service for HTTP message processing</description></item>
31
    /// </list>
32
    /// <para>
33
    /// The configuration is automatically bound from the "HmacAuthentication" section in your application configuration.
34
    /// Ensure your appsettings.json includes the required Client and Secret values:
35
    /// </para>
36
    /// <code>
37
    /// {
38
    ///   "HmacAuthentication": {
39
    ///     "Client": "your-client-id",
40
    ///     "Secret": "your-secret-key",
41
    ///     "SignedHeaders": ["host", "x-timestamp", "x-content-sha256"]
42
    ///   }
43
    /// }
44
    /// </code>
45
    /// </remarks>
46
    /// <example>
47
    /// <para>Basic usage with configuration binding:</para>
48
    /// <code>
49
    /// services.AddHmacAuthentication();
50
    /// </code>
51
    /// <para>Usage with additional programmatic configuration:</para>
52
    /// <code>
53
    /// services.AddHmacAuthentication(options =>
54
    /// {
55
    ///     options.Client = "override-client-id";
56
    ///     options.SignedHeaders = ["host", "x-timestamp", "x-content-sha256", "content-type"];
57
    /// });
58
    /// </code>
59
    /// <para>Usage with HttpClient factory:</para>
60
    /// <code>
61
    /// services.AddHmacAuthentication();
62
    /// services.AddHttpClient("ApiClient")
63
    ///     .AddHttpMessageHandler&lt;HmacAuthenticationHttpHandler&gt;();
64
    /// </code>
65
    /// </example>
66
    public static IServiceCollection AddHmacAuthentication(
67
        this IServiceCollection services,
68
        Action<HmacAuthenticationOptions>? configure = null)
69
    {
70
        if (services == null)
9!
NEW
71
            throw new ArgumentNullException(nameof(services));
×
72

73
        services
9✔
74
            .AddOptions<HmacAuthenticationOptions>()
9✔
75
            .BindConfiguration(HmacAuthenticationOptions.ConfigurationName)
9✔
76
            .ValidateOnStart();
9✔
77

78
        if (configure != null)
9✔
79
            services.PostConfigure(configure);
4✔
80

81
        services.AddTransient<HmacAuthenticationHttpHandler>();
9✔
82

83
        return services;
9✔
84
    }
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc