HttpContextExtension.cs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. // 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
  2. //
  3. // 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
  4. using Microsoft.AspNetCore.Authentication;
  5. namespace Admin.NET.Core.Service;
  6. public static class HttpContextExtension
  7. {
  8. public static async Task<AuthenticationScheme[]> GetExternalProvidersAsync(this HttpContext context)
  9. {
  10. ArgumentNullException.ThrowIfNull(context);
  11. var schemes = context.RequestServices.GetRequiredService<IAuthenticationSchemeProvider>();
  12. return (from scheme in await schemes.GetAllSchemesAsync()
  13. where !string.IsNullOrEmpty(scheme.DisplayName)
  14. select scheme).ToArray();
  15. }
  16. public static async Task<bool> IsProviderSupportedAsync(this HttpContext context, string provider)
  17. {
  18. ArgumentNullException.ThrowIfNull(context);
  19. return (from scheme in await context.GetExternalProvidersAsync()
  20. where string.Equals(scheme.Name, provider, StringComparison.OrdinalIgnoreCase)
  21. select scheme).Any();
  22. }
  23. }