WeChatAppBuilderExtensions.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. using Microsoft.Extensions.Options;
  5. using Winsoft.GOV.XF.WXCore.OAuth;
  6. namespace Microsoft.AspNetCore.Builder
  7. {
  8. /// <summary>
  9. /// Extension methods to add WeChat authentication capabilities to an HTTP application pipeline.
  10. /// </summary>
  11. public static class WeChatAppBuilderExtensions
  12. {
  13. /// <summary>
  14. /// Adds the <see cref="WeChatMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables WeChat authentication capabilities.
  15. /// </summary>
  16. /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
  17. /// <returns>A reference to this instance after the operation has completed.</returns>
  18. public static IApplicationBuilder UseWeChatAuthentication(this IApplicationBuilder app)
  19. {
  20. if (app == null)
  21. {
  22. throw new ArgumentNullException(nameof(app));
  23. }
  24. return app.UseMiddleware<WeChatMiddleware>();
  25. }
  26. /// <summary>
  27. /// Adds the <see cref="WeChatMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables WeChat authentication capabilities.
  28. /// </summary>
  29. /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
  30. /// <param name="options">A <see cref="WeChatOptions"/> that specifies options for the middleware.</param>
  31. /// <returns>A reference to this instance after the operation has completed.</returns>
  32. public static IApplicationBuilder UseWeChatAuthentication(this IApplicationBuilder app, WeChatOptions options)
  33. {
  34. if (app == null)
  35. {
  36. throw new ArgumentNullException(nameof(app));
  37. }
  38. if (options == null)
  39. {
  40. throw new ArgumentNullException(nameof(options));
  41. }
  42. return app.UseMiddleware<WeChatMiddleware>(Options.Create(options));
  43. }
  44. }
  45. }