Skip to content

Commit

Permalink
Create overloads for HttpClient builders to remove service name
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKotsenas committed May 18, 2022
1 parent 88d0f87 commit 2f031c3
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,29 @@ namespace Microsoft.Identity.Web
/// </summary>
public static class MicrosoftIdentityAuthenticationMessageHandlerHttpClientBuilderExtensions
{
private const string ObseleteMessage = "This method which accepts a service name is deprecated. Use the overload that uses the HttpClient name as the service name instead.";

/// <summary>
/// Adds a named Microsoft Identity user authentication message handler related to a specific configuration section.
/// </summary>
/// <param name="builder">Builder.</param>
/// <param name="serviceName">Name of the configuration for the service.</param>
/// <param name="configuration">Configuration.</param>
/// <returns>The builder for chaining.</returns>
public static IHttpClientBuilder AddMicrosoftIdentityUserAuthenticationHandler(
this IHttpClientBuilder builder,
IConfiguration configuration)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}

return builder.AddMicrosoftIdentityUserAuthenticationHandler(builder.Name, configuration);
}

/// <inheritdoc cref="AddMicrosoftIdentityUserAuthenticationHandler(IHttpClientBuilder, IConfiguration)" />
/// <param name="serviceName">Name of the configuration for the service.</param>
[Obsolete(ObseleteMessage)]
public static IHttpClientBuilder AddMicrosoftIdentityUserAuthenticationHandler(
this IHttpClientBuilder builder,
string serviceName,
Expand All @@ -41,9 +57,23 @@ public static IHttpClientBuilder AddMicrosoftIdentityUserAuthenticationHandler(
/// Adds a named Microsoft Identity user authentication message handler initialized with delegates.
/// </summary>
/// <param name="builder">Builder.</param>
/// <param name="serviceName">Name of the configuration for the service.</param>
/// <param name="configureOptions">Action to configure the options.</param>
/// <returns>The builder for chaining.</returns>
public static IHttpClientBuilder AddMicrosoftIdentityUserAuthenticationHandler(
this IHttpClientBuilder builder,
Action<MicrosoftIdentityAuthenticationMessageHandlerOptions> configureOptions)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}

return builder.AddMicrosoftIdentityUserAuthenticationHandler(builder.Name, configureOptions);
}

/// <inheritdoc cref="AddMicrosoftIdentityUserAuthenticationHandler(IHttpClientBuilder, Action{MicrosoftIdentityAuthenticationMessageHandlerOptions})"/>
/// <param name="serviceName">Name of the configuration for the service.</param>
[Obsolete(ObseleteMessage)]
public static IHttpClientBuilder AddMicrosoftIdentityUserAuthenticationHandler(
this IHttpClientBuilder builder,
string serviceName,
Expand All @@ -64,9 +94,23 @@ public static IHttpClientBuilder AddMicrosoftIdentityUserAuthenticationHandler(
/// Adds a named Microsoft Identity application authentication message handler related to a specific configuration section.
/// </summary>
/// <param name="builder">Builder.</param>
/// <param name="serviceName">Name of the configuration for the service.</param>
/// <param name="configuration">Configuration.</param>
/// <returns>The builder for chaining.</returns>
public static IHttpClientBuilder AddMicrosoftIdentityAppAuthenticationHandler(
this IHttpClientBuilder builder,
IConfiguration configuration)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}

return builder.AddMicrosoftIdentityAppAuthenticationHandler(builder.Name, configuration);
}

/// <inheritdoc cref="AddMicrosoftIdentityAppAuthenticationHandler(IHttpClientBuilder, IConfiguration)"/>
/// <param name="serviceName">Name of the configuration for the service.</param>
[Obsolete(ObseleteMessage)]
public static IHttpClientBuilder AddMicrosoftIdentityAppAuthenticationHandler(
this IHttpClientBuilder builder,
string serviceName,
Expand All @@ -87,9 +131,23 @@ public static IHttpClientBuilder AddMicrosoftIdentityAppAuthenticationHandler(
/// Adds a named Microsoft Identity application authentication message handler initialized with delegates.
/// </summary>
/// <param name="builder">Builder.</param>
/// <param name="serviceName">Name of the configuration for the service.</param>
/// <param name="configureOptions">Action to configure the options.</param>
/// <returns>The builder for chaining.</returns>
public static IHttpClientBuilder AddMicrosoftIdentityAppAuthenticationHandler(
this IHttpClientBuilder builder,
Action<MicrosoftIdentityAuthenticationMessageHandlerOptions> configureOptions)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}

return builder.AddMicrosoftIdentityAppAuthenticationHandler(builder.Name, configureOptions);
}

/// <inheritdoc cref="AddMicrosoftIdentityAppAuthenticationHandler(IHttpClientBuilder, Action{MicrosoftIdentityAuthenticationMessageHandlerOptions})"/>
/// <param name="serviceName">Name of the configuration for the service.</param>
[Obsolete(ObseleteMessage)]
public static IHttpClientBuilder AddMicrosoftIdentityAppAuthenticationHandler(
this IHttpClientBuilder builder,
string serviceName,
Expand Down
28 changes: 20 additions & 8 deletions src/Microsoft.Identity.Web/Microsoft.Identity.Web.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2f031c3

Please sign in to comment.