forked from FarmMaps/FarmMapsApiClient
		
	
		
			
				
	
	
		
			24 lines
		
	
	
		
			908 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			908 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 (!OidcConstants.AuthenticationSchemes.AuthorizationHeaderBearer.Equals(request.Headers?.Authorization.Scheme) ||
 | |
|                 string.IsNullOrEmpty(request.Headers?.Authorization.Parameter))
 | |
|             {
 | |
|                 return new HttpResponseMessage(HttpStatusCode.Unauthorized)
 | |
|                 {
 | |
|                     Content = new StringContent("You must authenticated before using the API")
 | |
|                 };
 | |
|             }
 | |
|             return await base.SendAsync(request, cancellationToken);
 | |
|         }
 | |
|     }
 | |
| } |