forked from FarmMaps/FarmMapsApiClient
		
	Initial commit
This commit is contained in:
		@@ -0,0 +1,24 @@
 | 
			
		||||
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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user