removed thing that checks if route is authorised cos we dont need it

This commit is contained in:
tom.pallister
2016-10-14 20:08:09 +01:00
parent 8c194a365b
commit f545ba8620
18 changed files with 93 additions and 210 deletions

View File

@ -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;
}
}
}