|
7 | 7 | using System;
|
8 | 8 | using AspNet.Security.OAuth.MailChimp;
|
9 | 9 | using JetBrains.Annotations;
|
10 |
| -using Microsoft.Extensions.Options; |
| 10 | +using Microsoft.AspNetCore.Authentication; |
11 | 11 |
|
12 |
| -namespace Microsoft.AspNetCore.Builder |
| 12 | +namespace Microsoft.Extensions.DependencyInjection |
13 | 13 | {
|
14 | 14 | /// <summary>
|
15 | 15 | /// Extension methods to add MailChimp authentication capabilities to an HTTP application pipeline.
|
16 | 16 | /// </summary>
|
17 | 17 | public static class MailChimpAuthenticationExtensions
|
18 | 18 | {
|
19 | 19 | /// <summary>
|
20 |
| - /// Adds the <see cref="MailChimpAuthenticationMiddleware"/> middleware to the specified |
21 |
| - /// <see cref="IApplicationBuilder"/>, which enables MailChimp authentication capabilities. |
| 20 | + /// Adds <see cref="MailChimpAuthenticationHandler"/> to the specified |
| 21 | + /// <see cref="AuthenticationBuilder"/>, which enables MailChimp authentication capabilities. |
22 | 22 | /// </summary>
|
23 |
| - /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param> |
24 |
| - /// <param name="options">A <see cref="MailChimpAuthenticationOptions"/> that specifies options for the middleware.</param> |
25 |
| - /// <returns>A reference to this instance after the operation has completed.</returns> |
26 |
| - public static IApplicationBuilder UseMailChimpAuthentication( |
27 |
| - [NotNull] this IApplicationBuilder app, |
28 |
| - [NotNull] MailChimpAuthenticationOptions options) |
| 23 | + /// <param name="builder">The authentication builder.</param> |
| 24 | + /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> |
| 25 | + public static AuthenticationBuilder AddMailChimp([NotNull] this AuthenticationBuilder builder) |
29 | 26 | {
|
30 |
| - if (app == null) |
31 |
| - { |
32 |
| - throw new ArgumentNullException(nameof(app)); |
33 |
| - } |
34 |
| - |
35 |
| - if (options == null) |
36 |
| - { |
37 |
| - throw new ArgumentNullException(nameof(options)); |
38 |
| - } |
39 |
| - |
40 |
| - return app.UseMiddleware<MailChimpAuthenticationMiddleware>(Options.Create(options)); |
| 27 | + return builder.AddMailChimp(MailChimpAuthenticationDefaults.AuthenticationScheme, options => { }); |
41 | 28 | }
|
42 | 29 |
|
43 | 30 | /// <summary>
|
44 |
| - /// Adds the <see cref="MailChimpAuthenticationMiddleware"/> middleware to the specified |
45 |
| - /// <see cref="IApplicationBuilder"/>, which enables MailChimp authentication capabilities. |
| 31 | + /// Adds <see cref="MailChimpAuthenticationHandler"/> to the specified |
| 32 | + /// <see cref="AuthenticationBuilder"/>, which enables MailChimp authentication capabilities. |
46 | 33 | /// </summary>
|
47 |
| - /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param> |
48 |
| - /// <param name="configuration">An action delegate to configure the provided <see cref="MailChimpAuthenticationOptions"/>.</param> |
49 |
| - /// <returns>A reference to this instance after the operation has completed.</returns> |
50 |
| - public static IApplicationBuilder UseMailChimpAuthentication( |
51 |
| - [NotNull] this IApplicationBuilder app, |
| 34 | + /// <param name="builder">The authentication builder.</param> |
| 35 | + /// <param name="configuration">The delegate used to configure the OpenID 2.0 options.</param> |
| 36 | + /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> |
| 37 | + public static AuthenticationBuilder AddMailChimp( |
| 38 | + [NotNull] this AuthenticationBuilder builder, |
52 | 39 | [NotNull] Action<MailChimpAuthenticationOptions> configuration)
|
53 | 40 | {
|
54 |
| - if (app == null) |
55 |
| - { |
56 |
| - throw new ArgumentNullException(nameof(app)); |
57 |
| - } |
58 |
| - |
59 |
| - if (configuration == null) |
60 |
| - { |
61 |
| - throw new ArgumentNullException(nameof(configuration)); |
62 |
| - } |
| 41 | + return builder.AddMailChimp(MailChimpAuthenticationDefaults.AuthenticationScheme, configuration); |
| 42 | + } |
63 | 43 |
|
64 |
| - var options = new MailChimpAuthenticationOptions(); |
65 |
| - configuration(options); |
| 44 | + /// <summary> |
| 45 | + /// Adds <see cref="MailChimpAuthenticationHandler"/> to the specified |
| 46 | + /// <see cref="AuthenticationBuilder"/>, which enables MailChimp authentication capabilities. |
| 47 | + /// </summary> |
| 48 | + /// <param name="builder">The authentication builder.</param> |
| 49 | + /// <param name="scheme">The authentication scheme associated with this instance.</param> |
| 50 | + /// <param name="configuration">The delegate used to configure the MailChimp options.</param> |
| 51 | + /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> |
| 52 | + public static AuthenticationBuilder AddMailChimp( |
| 53 | + [NotNull] this AuthenticationBuilder builder, string scheme, |
| 54 | + [NotNull] Action<MailChimpAuthenticationOptions> configuration) |
| 55 | + { |
| 56 | + return builder.AddMailChimp(scheme, MailChimpAuthenticationDefaults.DisplayName, configuration); |
| 57 | + } |
66 | 58 |
|
67 |
| - return app.UseMiddleware<MailChimpAuthenticationMiddleware>(Options.Create(options)); |
| 59 | + /// <summary> |
| 60 | + /// Adds <see cref="MailChimpAuthenticationHandler"/> to the specified |
| 61 | + /// <see cref="AuthenticationBuilder"/>, which enables MailChimp authentication capabilities. |
| 62 | + /// </summary> |
| 63 | + /// <param name="builder">The authentication builder.</param> |
| 64 | + /// <param name="scheme">The authentication scheme associated with this instance.</param> |
| 65 | + /// <param name="name">The optional display name associated with this instance.</param> |
| 66 | + /// <param name="configuration">The delegate used to configure the MailChimp options.</param> |
| 67 | + /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> |
| 68 | + public static AuthenticationBuilder AddMailChimp( |
| 69 | + [NotNull] this AuthenticationBuilder builder, |
| 70 | + [NotNull] string scheme, [CanBeNull] string name, |
| 71 | + [NotNull] Action<MailChimpAuthenticationOptions> configuration) |
| 72 | + { |
| 73 | + return builder.AddOAuth<MailChimpAuthenticationOptions, MailChimpAuthenticationHandler>(scheme, name, configuration); |
68 | 74 | }
|
69 | 75 | }
|
70 | 76 | }
|
0 commit comments