mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-08-01 02:55:56 +08:00
started adding authentication stack, thing that decides if we should be authenticated is in
This commit is contained in:
@ -0,0 +1,11 @@
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
{
|
||||
using Responses;
|
||||
public class CouldNotFindConfigurationError : Error
|
||||
{
|
||||
public CouldNotFindConfigurationError(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
{
|
||||
using DownstreamRouteFinder;
|
||||
using Responses;
|
||||
|
||||
public interface IRouteRequiresAuthentication
|
||||
{
|
||||
Response<bool> IsAuthenticated(DownstreamRoute downstreamRoute, string httpMethod);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Configuration;
|
||||
using DownstreamRouteFinder;
|
||||
using Responses;
|
||||
|
||||
public class RouteRequiresAuthentication : IRouteRequiresAuthentication
|
||||
{
|
||||
private readonly IOcelotConfiguration _configuration;
|
||||
|
||||
public RouteRequiresAuthentication(IOcelotConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public Response<bool> IsAuthenticated(DownstreamRoute downstreamRoute, string httpMethod)
|
||||
{
|
||||
var reRoute =
|
||||
_configuration.ReRoutes.FirstOrDefault(
|
||||
x =>
|
||||
x.DownstreamTemplate == downstreamRoute.DownstreamUrlTemplate &&
|
||||
string.Equals(x.UpstreamHttpMethod, httpMethod, StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
if (reRoute == null)
|
||||
{
|
||||
return new ErrorResponse<bool>(new List<Error> {new CouldNotFindConfigurationError($"Could not find configuration for {downstreamRoute.DownstreamUrlTemplate} using method {httpMethod}")});
|
||||
}
|
||||
|
||||
return new OkResponse<bool>(reRoute.IsAuthenticated);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user