Browse Source

Remove the Add[Provider]() overload returning a derived builder

pull/1805/head 4.5.0
Kévin Chalet 3 years ago
parent
commit
fb78fb9d0d
  1. 59
      gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs
  2. 10
      sandbox/OpenIddict.Sandbox.AspNet.Server/Startup.cs
  3. 10
      sandbox/OpenIddict.Sandbox.AspNetCore.Server/Startup.cs
  4. 12
      sandbox/OpenIddict.Sandbox.WinForms.Client/Program.cs
  5. 12
      sandbox/OpenIddict.Sandbox.Wpf.Client/Program.cs

59
gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs

@ -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
{
@ -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 ~}}

10
sandbox/OpenIddict.Sandbox.AspNet.Server/Startup.cs

@ -71,10 +71,12 @@ namespace OpenIddict.Sandbox.AspNet.Server
// 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.

10
sandbox/OpenIddict.Sandbox.AspNetCore.Server/Startup.cs

@ -89,10 +89,12 @@ public class Startup
// 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.

12
sandbox/OpenIddict.Sandbox.WinForms.Client/Program.cs

@ -81,11 +81,13 @@ var host = new HostBuilder()
// 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

12
sandbox/OpenIddict.Sandbox.Wpf.Client/Program.cs

@ -82,11 +82,13 @@ var host = new HostBuilder()
// 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

Loading…
Cancel
Save