/
HttpContextExtensions.cs
30 lines (24 loc) · 1.15 KB
/
HttpContextExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
*/
namespace Mvc.Client.Extensions;
public static class HttpContextExtensions
{
public static async Task<AuthenticationScheme[]> GetExternalProvidersAsync(this HttpContext context)
{
ArgumentNullException.ThrowIfNull(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)
{
ArgumentNullException.ThrowIfNull(context);
return (from scheme in await context.GetExternalProvidersAsync()
where string.Equals(scheme.Name, provider, StringComparison.OrdinalIgnoreCase)
select scheme).Any();
}
}