forked from FarmMaps/FarmMapsApiClient
24 lines
905 B
C#
24 lines
905 B
C#
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using IdentityModel;
|
|
|
|
namespace FarmmapsApi.HttpMessageHandlers
|
|
{
|
|
public class FarmmapsAuthenticationHandler : DelegatingHandler
|
|
{
|
|
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
if (!request.Headers.Authorization.Scheme.Equals(OidcConstants.AuthenticationSchemes.AuthorizationHeaderBearer) ||
|
|
string.IsNullOrEmpty(request.Headers.Authorization.Parameter))
|
|
{
|
|
return new HttpResponseMessage(HttpStatusCode.Unauthorized)
|
|
{
|
|
Content = new StringContent("You must authenticate before using the API")
|
|
};
|
|
}
|
|
return await base.SendAsync(request, cancellationToken);
|
|
}
|
|
}
|
|
} |