mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 13:30:49 +08:00 
			
		
		
		
	removed thing that checks if route is authorised cos we dont need it
This commit is contained in:
		@@ -1,41 +1,35 @@
 | 
			
		||||
namespace Ocelot.Library.Middleware
 | 
			
		||||
{
 | 
			
		||||
    using System.Threading.Tasks;
 | 
			
		||||
    using Infrastructure.Authentication;
 | 
			
		||||
    using Infrastructure.Configuration;
 | 
			
		||||
    using Infrastructure.DownstreamRouteFinder;
 | 
			
		||||
    using Infrastructure.Repository;
 | 
			
		||||
    using Infrastructure.Responses;
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
 | 
			
		||||
    public class AuthenticationMiddleware : OcelotMiddleware
 | 
			
		||||
    {
 | 
			
		||||
        private readonly RequestDelegate _next;
 | 
			
		||||
        private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
 | 
			
		||||
        private readonly IRouteRequiresAuthentication _requiresAuthentication;
 | 
			
		||||
 | 
			
		||||
        public AuthenticationMiddleware(RequestDelegate next, 
 | 
			
		||||
            IScopedRequestDataRepository scopedRequestDataRepository, 
 | 
			
		||||
            IRouteRequiresAuthentication requiresAuthentication) 
 | 
			
		||||
            IScopedRequestDataRepository scopedRequestDataRepository) 
 | 
			
		||||
            : base(scopedRequestDataRepository)
 | 
			
		||||
        {
 | 
			
		||||
            _next = next;
 | 
			
		||||
            _scopedRequestDataRepository = scopedRequestDataRepository;
 | 
			
		||||
            _requiresAuthentication = requiresAuthentication;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task Invoke(HttpContext context)
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
 | 
			
		||||
 | 
			
		||||
            var isAuthenticated = _requiresAuthentication.IsAuthenticated(downstreamRoute.Data, context.Request.Method);
 | 
			
		||||
 | 
			
		||||
            if (isAuthenticated.IsError)
 | 
			
		||||
            if (downstreamRoute.IsError)
 | 
			
		||||
            {
 | 
			
		||||
                SetPipelineError(downstreamRoute.Errors);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (IsAuthenticatedRoute(isAuthenticated))
 | 
			
		||||
            if (IsAuthenticatedRoute(downstreamRoute.Data.ReRoute))
 | 
			
		||||
            {
 | 
			
		||||
                //todo - build auth pipeline and then call normal pipeline if all good?
 | 
			
		||||
                await _next.Invoke(context);
 | 
			
		||||
@@ -46,9 +40,9 @@
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static bool IsAuthenticatedRoute(Response<bool> isAuthenticated)
 | 
			
		||||
        private static bool IsAuthenticatedRoute(ReRoute reRoute)
 | 
			
		||||
        {
 | 
			
		||||
            return isAuthenticated.Data;
 | 
			
		||||
            return reRoute.IsAuthenticated;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user