Skip to content

Commit

Permalink
Remove the Add[Provider]() overload returning a derived builder
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchalet committed Jun 17, 2023
1 parent 5c7451d commit fb78fb9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,47 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{
{{~ for provider in providers ~}}
/// <summary>
/// Enables the {{ provider.display_name }} integration and registers the associated services in the DI container.
/// Adds a new {{ provider.display_name }} client registration.
{{~ if provider.documentation ~}}
/// For more information, read <see href=""{{ provider.documentation }}"">the documentation</see>.
{{~ end ~}}
/// </summary>
/// <remarks>This extension can be safely called multiple times.</remarks>
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete($""This method was replaced by {nameof(Add{{ provider.name }})} and will be removed in a future version."")]
public OpenIddictClientWebIntegrationBuilder.{{ provider.name }} Use{{ provider.name }}()
=> Add{{ provider.name }}();
/// <param name=""configuration"">The delegate used to configure the OpenIddict/{{ provider.display_name }} options.</param>
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder""/> instance.</returns>
public OpenIddictClientWebIntegrationBuilder Add{{ provider.name }}(Action<OpenIddictClientWebIntegrationBuilder.{{ provider.name }}> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
Services.Configure<OpenIddictClientOptions>(options =>
{
var registration = new OpenIddictClientRegistration
{
ProviderSettings = new OpenIddictClientWebIntegrationSettings.{{ provider.name }}(),
ProviderType = ProviderTypes.{{ provider.name }}
};
configuration(new OpenIddictClientWebIntegrationBuilder.{{ provider.name }}(registration));
options.Registrations.Add(registration);
});
return this;
}
/// <summary>
/// Adds a new {{ provider.display_name }} client registration.
/// Enables the {{ provider.display_name }} integration and registers the associated services in the DI container.
{{~ if provider.documentation ~}}
/// For more information, read <see href=""{{ provider.documentation }}"">the documentation</see>.
{{~ end ~}}
/// </summary>
/// <remarks>This extension can be safely called multiple times.</remarks>
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public OpenIddictClientWebIntegrationBuilder.{{ provider.name }} Add{{ provider.name }}()
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete($""This method was replaced by {nameof(Add{{ provider.name }})} and will be removed in a future version."")]
public OpenIddictClientWebIntegrationBuilder.{{ provider.name }} Use{{ provider.name }}()
{
var registration = new OpenIddictClientRegistration
{
Expand All @@ -117,26 +138,6 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
[Obsolete($""This method was replaced by {nameof(Add{{ provider.name }})} and will be removed in a future version."")]
public OpenIddictClientWebIntegrationBuilder Use{{ provider.name }}(Action<OpenIddictClientWebIntegrationBuilder.{{ provider.name }}> configuration)
=> Add{{ provider.name }}(configuration);
/// <summary>
/// Adds a new {{ provider.display_name }} client registration.
{{~ if provider.documentation ~}}
/// For more information, read <see href=""{{ provider.documentation }}"">the documentation</see>.
{{~ end ~}}
/// </summary>
/// <param name=""configuration"">The delegate used to configure the OpenIddict/{{ provider.display_name }} options.</param>
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder""/> instance.</returns>
public OpenIddictClientWebIntegrationBuilder Add{{ provider.name }}(Action<OpenIddictClientWebIntegrationBuilder.{{ provider.name }}> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(Add{{ provider.name }}());
return this;
}
{{~ end ~}}
{{~ for provider in providers ~}}
Expand Down
10 changes: 6 additions & 4 deletions sandbox/OpenIddict.Sandbox.AspNet.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ public void Configuration(IAppBuilder app)
// parameter containing their URL as part of authorization responses. For more information,
// see https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#section-4.4.
options.UseWebProviders()
.AddGitHub()
.SetClientId("c4ade52327b01ddacff3")
.SetClientSecret("da6bed851b75e317bf6b2cb67013679d9467c122")
.SetRedirectUri("callback/login/github");
.AddGitHub(options =>
{
options.SetClientId("c4ade52327b01ddacff3")
.SetClientSecret("da6bed851b75e317bf6b2cb67013679d9467c122")
.SetRedirectUri("callback/login/github");
});
})

// Register the OpenIddict server components.
Expand Down
10 changes: 6 additions & 4 deletions sandbox/OpenIddict.Sandbox.AspNetCore.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ public void ConfigureServices(IServiceCollection services)
// parameter containing their URL as part of authorization responses. For more information,
// see https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#section-4.4.
options.UseWebProviders()
.AddGitHub()
.SetClientId("c4ade52327b01ddacff3")
.SetClientSecret("da6bed851b75e317bf6b2cb67013679d9467c122")
.SetRedirectUri("callback/login/github");
.AddGitHub(options =>
{
options.SetClientId("c4ade52327b01ddacff3")
.SetClientSecret("da6bed851b75e317bf6b2cb67013679d9467c122")
.SetRedirectUri("callback/login/github");
});
})

// Register the OpenIddict server components.
Expand Down
12 changes: 7 additions & 5 deletions sandbox/OpenIddict.Sandbox.WinForms.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@
// parameter containing their URL as part of authorization responses. For more information,
// see https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#section-4.4.
options.UseWebProviders()
.AddGitHub()
.SetClientId("cf8efb4d76c0cb7109d3")
.SetClientSecret("e8c0f6b869164411bb9052e42414cbcc52d518cd")
// Note: GitHub doesn't support the recommended ":/" syntax and requires using "://".
.SetRedirectUri("com.openiddict.sandbox.winforms.client://callback/login/github");
.AddGitHub(options =>
{
options.SetClientId("cf8efb4d76c0cb7109d3")
.SetClientSecret("e8c0f6b869164411bb9052e42414cbcc52d518cd")
// Note: GitHub doesn't support the recommended ":/" syntax and requires using "://".
.SetRedirectUri("com.openiddict.sandbox.winforms.client://callback/login/github");
});
});

// Register the worker responsible for creating the database used to store tokens
Expand Down
12 changes: 7 additions & 5 deletions sandbox/OpenIddict.Sandbox.Wpf.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@
// parameter containing their URL as part of authorization responses. For more information,
// see https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#section-4.4.
options.UseWebProviders()
.AddGitHub()
.SetClientId("8abc54b6d5f4e39d78aa")
.SetClientSecret("f37ef38bdb18a0f5f2d430a8edbed4353c012dc3")
// Note: GitHub doesn't support the recommended ":/" syntax and requires using "://".
.SetRedirectUri("com.openiddict.sandbox.wpf.client://callback/login/github");
.AddGitHub(options =>
{
options.SetClientId("8abc54b6d5f4e39d78aa")
.SetClientSecret("f37ef38bdb18a0f5f2d430a8edbed4353c012dc3")
// Note: GitHub doesn't support the recommended ":/" syntax and requires using "://".
.SetRedirectUri("com.openiddict.sandbox.wpf.client://callback/login/github");
});
});

// Register the worker responsible for creating the database used to store tokens
Expand Down

0 comments on commit fb78fb9

Please sign in to comment.