|
6 | 6 |
|
7 | 7 | using System; |
8 | 8 | using AspNet.Security.OAuth.<%= name %>; |
9 | | -using Microsoft.Extensions.Internal; |
| 9 | +using JetBrains.Annotations; |
| 10 | +using Microsoft.Extensions.Options; |
10 | 11 |
|
11 | | -namespace Microsoft.AspNet.Builder { |
| 12 | +namespace Microsoft.AspNetCore.Builder { |
| 13 | + /// <summary> |
| 14 | + /// Extension methods to add <%= name %> authentication capabilities to an HTTP application pipeline. |
| 15 | + /// </summary> |
12 | 16 | public static class <%= name %>AuthenticationExtensions { |
| 17 | + /// <summary> |
| 18 | + /// Adds the <see cref="<%= name %>AuthenticationMiddleware"/> middleware to the specified |
| 19 | + /// <see cref="IApplicationBuilder"/>, which enables <%= name %> authentication capabilities. |
| 20 | + /// </summary> |
| 21 | + /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param> |
| 22 | + /// <param name="options">A <see cref="<%= name %>AuthenticationOptions"/> that specifies options for the middleware.</param> |
| 23 | + /// <returns>A reference to this instance after the operation has completed.</returns> |
13 | 24 | public static IApplicationBuilder Use<%= name %>Authentication( |
14 | 25 | [NotNull] this IApplicationBuilder app, |
15 | 26 | [NotNull] <%= name %>AuthenticationOptions options) { |
16 | | - return app.UseMiddleware<<%= name %>AuthenticationMiddleware>(options); |
| 27 | + if (app == null) { |
| 28 | + throw new ArgumentNullException(nameof(app)); |
| 29 | + } |
| 30 | + |
| 31 | + if (options == null) { |
| 32 | + throw new ArgumentNullException(nameof(options)); |
| 33 | + } |
| 34 | + |
| 35 | + return app.UseMiddleware<<%= name %>AuthenticationMiddleware>(Options.Create(options)); |
17 | 36 | } |
18 | 37 |
|
| 38 | + /// <summary> |
| 39 | + /// Adds the <see cref="<%= name %>AuthenticationMiddleware"/> middleware to the specified |
| 40 | + /// <see cref="IApplicationBuilder"/>, which enables <%= name %> authentication capabilities. |
| 41 | + /// </summary> |
| 42 | + /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param> |
| 43 | + /// <param name="configuration">An action delegate to configure the provided <see cref="<%= name %>AuthenticationOptions"/>.</param> |
| 44 | + /// <returns>A reference to this instance after the operation has completed.</returns> |
19 | 45 | public static IApplicationBuilder Use<%= name %>Authentication( |
20 | 46 | [NotNull] this IApplicationBuilder app, |
21 | 47 | [NotNull] Action<<%= name %>AuthenticationOptions> configuration) { |
| 48 | + if (app == null) { |
| 49 | + throw new ArgumentNullException(nameof(app)); |
| 50 | + } |
| 51 | + |
| 52 | + if (configuration == null) { |
| 53 | + throw new ArgumentNullException(nameof(configuration)); |
| 54 | + } |
| 55 | + |
22 | 56 | var options = new <%= name %>AuthenticationOptions(); |
23 | 57 | configuration(options); |
24 | 58 |
|
25 | | - return app.UseMiddleware<<%= name %>AuthenticationMiddleware>(options); |
| 59 | + return app.UseMiddleware<<%= name %>AuthenticationMiddleware>(Options.Create(options)); |
26 | 60 | } |
27 | 61 | } |
28 | 62 | } |
0 commit comments