You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
38 lines
1.3 KiB
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<AuthenticationScheme[]> GetExternalProvidersAsync(this HttpContext context)
|
|
{
|
|
if (context == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(context));
|
|
}
|
|
|
|
var schemes = context.RequestServices.GetRequiredService<IAuthenticationSchemeProvider>();
|
|
|
|
return (from scheme in await schemes.GetAllSchemesAsync()
|
|
where !string.IsNullOrEmpty(scheme.DisplayName)
|
|
select scheme).ToArray();
|
|
}
|
|
|
|
public static async Task<bool> 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();
|
|
}
|
|
}
|
|
} |