mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
holy mother of god all tests passing .net core 2.0 upgrade....
This commit is contained in:
parent
e0c16bea32
commit
6fcede701a
@ -1,16 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using IdentityServer4.AccessTokenValidation;
|
||||
using IdentityServer4.Extensions;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Ocelot.Authentication.Handler.Factory;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Errors;
|
||||
@ -48,7 +40,7 @@ namespace Ocelot.Authentication.Middleware
|
||||
{
|
||||
_logger.LogDebug($"{context.Request.Path} is an authenticated route. {MiddlewareName} checking if client is authenticated");
|
||||
|
||||
var result = await context.AuthenticateAsync(DownstreamRoute.ReRoute.AuthenticationOptions.Provider);
|
||||
var result = await context.AuthenticateAsync(DownstreamRoute.ReRoute.AuthenticationProviderKey);
|
||||
|
||||
context.User = result.Principal;
|
||||
|
||||
@ -82,43 +74,5 @@ namespace Ocelot.Authentication.Middleware
|
||||
return reRoute.IsAuthenticated;
|
||||
}
|
||||
}
|
||||
|
||||
public class TestHandler : AuthenticationHandler<TestOptions>
|
||||
{
|
||||
public TestHandler(IOptionsMonitor<TestOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||
{
|
||||
var principal = new ClaimsPrincipal();
|
||||
var id = new ClaimsIdentity("Ocelot");
|
||||
id.AddClaim(new Claim(ClaimTypes.NameIdentifier, Scheme.Name, ClaimValueTypes.String, Scheme.Name));
|
||||
if (Options.Instance != null)
|
||||
{
|
||||
id.AddClaim(new Claim("Count", Options.Instance.Count.ToString()));
|
||||
}
|
||||
principal.AddIdentity(id);
|
||||
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(principal, new AuthenticationProperties(), Scheme.Name)));
|
||||
}
|
||||
}
|
||||
|
||||
public class TestOptions : AuthenticationSchemeOptions
|
||||
{
|
||||
public Singleton Instance { get; set; }
|
||||
}
|
||||
|
||||
public class Singleton
|
||||
{
|
||||
public static int _count;
|
||||
|
||||
public Singleton()
|
||||
{
|
||||
_count++;
|
||||
Count = _count;
|
||||
}
|
||||
|
||||
public int Count { get; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ namespace Ocelot.Configuration.Builder
|
||||
private QoSOptions _qosOptions;
|
||||
public bool _enableRateLimiting;
|
||||
public RateLimitOptions _rateLimitOptions;
|
||||
private string _authenticationProviderKey;
|
||||
|
||||
public ReRouteBuilder WithLoadBalancer(string loadBalancer)
|
||||
{
|
||||
@ -176,6 +177,12 @@ namespace Ocelot.Configuration.Builder
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReRouteBuilder WithAuthenticationProviderKey(string authenticationProviderKey)
|
||||
{
|
||||
_authenticationProviderKey = authenticationProviderKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ReRoute Build()
|
||||
{
|
||||
@ -203,7 +210,8 @@ namespace Ocelot.Configuration.Builder
|
||||
_useQos,
|
||||
_qosOptions,
|
||||
_enableRateLimiting,
|
||||
_rateLimitOptions);
|
||||
_rateLimitOptions,
|
||||
_authenticationProviderKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -168,6 +168,7 @@ namespace Ocelot.Configuration.Creator
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithEnableRateLimiting(fileReRouteOptions.EnableRateLimiting)
|
||||
.WithRateLimitOptions(rateLimitOption)
|
||||
.WithAuthenticationProviderKey(fileReRoute.AuthenticationProviderKey)
|
||||
.Build();
|
||||
|
||||
await SetupLoadBalancer(reRoute);
|
||||
|
@ -29,7 +29,8 @@ namespace Ocelot.Configuration
|
||||
bool isQos,
|
||||
QoSOptions qosOptions,
|
||||
bool enableEndpointRateLimiting,
|
||||
RateLimitOptions ratelimitOptions)
|
||||
RateLimitOptions ratelimitOptions,
|
||||
string authenticationProviderKey)
|
||||
{
|
||||
ReRouteKey = reRouteKey;
|
||||
ServiceProviderConfiguraion = serviceProviderConfiguraion;
|
||||
@ -58,6 +59,7 @@ namespace Ocelot.Configuration
|
||||
QosOptionsOptions = qosOptions;
|
||||
EnableEndpointEndpointRateLimiting = enableEndpointRateLimiting;
|
||||
RateLimitOptions = ratelimitOptions;
|
||||
AuthenticationProviderKey = authenticationProviderKey;
|
||||
}
|
||||
|
||||
public string ReRouteKey {get;private set;}
|
||||
@ -84,5 +86,6 @@ namespace Ocelot.Configuration
|
||||
public ServiceProviderConfiguration ServiceProviderConfiguraion { get; private set; }
|
||||
public bool EnableEndpointEndpointRateLimiting { get; private set; }
|
||||
public RateLimitOptions RateLimitOptions { get; private set; }
|
||||
public string AuthenticationProviderKey { get; private set; }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user