using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using System; using System.Linq; using System.Threading.Tasks; namespace Infrastructure.Extensions { public static class HtmlContentExtensions { public static async Task GetExternalProvidersAsync(this HttpContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var schemes = context.RequestServices.GetRequiredService(); return (from scheme in await schemes.GetAllSchemesAsync() where !string.IsNullOrEmpty(scheme.DisplayName) select scheme).ToArray(); } public static async Task IsProviderSupportedAsync(this HttpContext context, string provider) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return (from scheme in await context.GetExternalProvidersAsync() where string.Equals(scheme.Name, provider, StringComparison.OrdinalIgnoreCase) select scheme).Any(); } } }