Skip to content

Commit 6d70347

Browse files
committed
Added AddOAuth*() overloads with default scheme name.
1 parent f7e2fd3 commit 6d70347

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

Http/src/AppCore.Extensions.Http.Authentication.OAuth.AspNetCore/DependencyInjection/OAuthHttpClientAuthenticationBuilderExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,18 @@ public static IHttpClientAuthenticationBuilder AddOAuthClientFromOpenIdConnect(
5252
OAuthParameters,
5353
OAuthClientHandler>(scheme);
5454
}
55+
56+
/// <summary>
57+
/// Adds OAuth client credentials authentication with default scheme name by inferring the configuration from
58+
/// a OpenID connect authentication scheme.
59+
/// </summary>
60+
/// <param name="builder">The <see cref="IHttpClientAuthenticationBuilder"/>.</param>
61+
/// <param name="configure"></param>
62+
/// <returns></returns>
63+
public static IHttpClientAuthenticationBuilder AddOAuthClientFromOpenIdConnect(
64+
this IHttpClientAuthenticationBuilder builder,
65+
Action<OpenIdConnectOAuthClientOptions>? configure = null)
66+
{
67+
return builder.AddOAuthClientFromOpenIdConnect(OAuthClientDefaults.AuthenticationScheme, configure);
68+
}
5569
}

Http/src/AppCore.Extensions.Http.Authentication.OAuth/DependencyInjection/OAuthHttpClientAuthenticationBuilderExtensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ public static IHttpClientAuthenticationBuilder AddOAuthClient(
7474
OAuthClientHandler>(scheme, configure);
7575
}
7676

77+
/// <summary>
78+
/// Adds OAuth client credentials authentication with default scheme.
79+
/// </summary>
80+
/// <param name="builder">The <see cref="IHttpClientAuthenticationBuilder"/>.</param>
81+
/// <param name="configure"></param>
82+
/// <returns></returns>
83+
public static IHttpClientAuthenticationBuilder AddOAuthClient(
84+
this IHttpClientAuthenticationBuilder builder,
85+
Action<OAuthClientOptions> configure)
86+
{
87+
return builder.AddOAuthClient(OAuthClientDefaults.AuthenticationScheme, configure);
88+
}
89+
7790
/// <summary>
7891
/// Adds OAuth password authentication scheme.
7992
/// </summary>
@@ -111,6 +124,19 @@ public static IHttpClientAuthenticationBuilder AddOAuthPassword(
111124
OAuthPasswordHandler>(scheme, configure);
112125
}
113126

127+
/// <summary>
128+
/// Adds OAuth password authentication with default scheme.
129+
/// </summary>
130+
/// <param name="builder">The <see cref="IHttpClientAuthenticationBuilder"/>.</param>
131+
/// <param name="configure"></param>
132+
/// <returns></returns>
133+
public static IHttpClientAuthenticationBuilder AddOAuthPassword(
134+
this IHttpClientAuthenticationBuilder builder,
135+
Action<OAuthPasswordOptions> configure)
136+
{
137+
return builder.AddOAuthPassword(OAuthClientDefaults.AuthenticationScheme, configure);
138+
}
139+
114140
/// <summary>
115141
/// Configures the OAuth token client.
116142
/// </summary>

Http/src/AppCore.Extensions.Http.Authentication.OAuth/DependencyInjection/OAuthHttpClientBuilderExtensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ public static IHttpClientBuilder AddOAuthClientAuthentication(
2828
return builder.AddAuthentication<OAuthParameters, OAuthClientHandler>(scheme, parameters);
2929
}
3030

31+
/// <summary>
32+
/// Adds OAuth client credentials authentications with the default scheme.
33+
/// </summary>
34+
/// <param name="builder">The <see cref="IHttpClientBuilder"/>.</param>
35+
/// <param name="parameters"></param>
36+
/// <returns></returns>
37+
public static IHttpClientBuilder AddOAuthClientAuthentication(
38+
this IHttpClientBuilder builder,
39+
OAuthParameters? parameters = null)
40+
{
41+
return builder.AddOAuthClientAuthentication(OAuthClientDefaults.AuthenticationScheme, parameters);
42+
}
43+
3144
/// <summary>
3245
/// Adds OAuth password authentications.
3346
/// </summary>
@@ -43,4 +56,17 @@ public static IHttpClientBuilder AddOAuthPasswordAuthentication(
4356
Ensure.Arg.NotNull(builder);
4457
return builder.AddAuthentication<OAuthParameters, OAuthPasswordHandler>(scheme, parameters);
4558
}
59+
60+
/// <summary>
61+
/// Adds OAuth password authentications with the default scheme.
62+
/// </summary>
63+
/// <param name="builder">The <see cref="IHttpClientBuilder"/>.</param>
64+
/// <param name="parameters"></param>
65+
/// <returns></returns>
66+
public static IHttpClientBuilder AddOAuthPasswordAuthentication(
67+
this IHttpClientBuilder builder,
68+
OAuthParameters? parameters = null)
69+
{
70+
return builder.AddOAuthClientAuthentication(OAuthPasswordDefaults.AuthenticationScheme, parameters);
71+
}
4672
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed under the MIT License.
2+
// Copyright (c) 2018-2022 the AppCore .NET project.
3+
4+
namespace AppCore.Extensions.Http.Authentication.OAuth;
5+
6+
/// <summary>
7+
/// Provides default values for the OAuth client credentials authentication.
8+
/// </summary>
9+
public static class OAuthClientDefaults
10+
{
11+
/// <summary>
12+
/// The default value used for OAuth client credentials scheme name.
13+
/// </summary>
14+
public const string AuthenticationScheme = "OAuthClient";
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed under the MIT License.
2+
// Copyright (c) 2018-2022 the AppCore .NET project.
3+
4+
namespace AppCore.Extensions.Http.Authentication.OAuth;
5+
6+
/// <summary>
7+
/// Provides default values for the OAuth password authentication.
8+
/// </summary>
9+
public static class OAuthPasswordDefaults
10+
{
11+
/// <summary>
12+
/// The default value used for OAuth password scheme name.
13+
/// </summary>
14+
public const string AuthenticationScheme = "OAuthPassword";
15+
}

0 commit comments

Comments
 (0)