mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 14:02:49 +08:00
renamed provider to handler
This commit is contained in:
parent
320b442526
commit
7289cd803b
@ -5,11 +5,11 @@ using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
{
|
||||
public class AuthenticationProviderFactory : IAuthenticationProviderFactory
|
||||
public class AuthenticationHandlerFactory : IAuthenticationHandlerFactory
|
||||
{
|
||||
private readonly IAuthenticationHandlerCreator _creator;
|
||||
|
||||
public AuthenticationProviderFactory(IAuthenticationHandlerCreator creator)
|
||||
public AuthenticationHandlerFactory(IAuthenticationHandlerCreator creator)
|
||||
{
|
||||
_creator = creator;
|
||||
}
|
@ -3,7 +3,7 @@ using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
{
|
||||
public interface IAuthenticationProviderFactory
|
||||
public interface IAuthenticationHandlerFactory
|
||||
{
|
||||
Response<AuthenticationHandler> Get(string provider, IApplicationBuilder app);
|
||||
}
|
@ -22,15 +22,15 @@ namespace Ocelot.Library.Infrastructure.Middleware
|
||||
private RequestDelegate _authenticationNext;
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IApplicationBuilder _app;
|
||||
private readonly IAuthenticationProviderFactory _authProviderFactory;
|
||||
private readonly IAuthenticationHandlerFactory _authHandlerFactory;
|
||||
|
||||
public AuthenticationMiddleware(RequestDelegate next, IApplicationBuilder app,
|
||||
IScopedRequestDataRepository scopedRequestDataRepository, IAuthenticationProviderFactory authProviderFactory)
|
||||
IScopedRequestDataRepository scopedRequestDataRepository, IAuthenticationHandlerFactory authHandlerFactory)
|
||||
: base(scopedRequestDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_authProviderFactory = authProviderFactory;
|
||||
_authHandlerFactory = authHandlerFactory;
|
||||
_app = app;
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ namespace Ocelot.Library.Infrastructure.Middleware
|
||||
|
||||
if (IsAuthenticatedRoute(downstreamRoute.Data.ReRoute))
|
||||
{
|
||||
var authenticationNext = _authProviderFactory.Get(downstreamRoute.Data.ReRoute.AuthenticationProvider, _app);
|
||||
var authenticationNext = _authHandlerFactory.Get(downstreamRoute.Data.ReRoute.AuthenticationProvider, _app);
|
||||
|
||||
if (!authenticationNext.IsError)
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ namespace Ocelot
|
||||
services.AddSingleton<IHttpResponder, HttpContextResponder>();
|
||||
services.AddSingleton<IRequestBuilder, HttpRequestBuilder>();
|
||||
services.AddSingleton<IErrorsToHttpStatusCodeMapper, ErrorsToHttpStatusCodeMapper>();
|
||||
services.AddSingleton<IAuthenticationProviderFactory, AuthenticationProviderFactory>();
|
||||
services.AddSingleton<IAuthenticationHandlerFactory, AuthenticationHandlerFactory>();
|
||||
services.AddSingleton<IAuthenticationHandlerCreator, AuthenticationHandlerCreator>();
|
||||
|
||||
// see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc
|
||||
|
@ -12,24 +12,24 @@ using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Authentication
|
||||
{
|
||||
public class AuthenticationProviderFactoryTests
|
||||
public class AuthenticationHandlerFactoryTests
|
||||
{
|
||||
private readonly IAuthenticationProviderFactory _authenticationProviderFactory;
|
||||
private readonly IAuthenticationHandlerFactory _authenticationHandlerFactory;
|
||||
private readonly Mock<IApplicationBuilder> _app;
|
||||
private readonly Mock<IAuthenticationHandlerCreator> _creator;
|
||||
|
||||
private string _provider;
|
||||
private Response<AuthenticationHandler> _result;
|
||||
|
||||
public AuthenticationProviderFactoryTests()
|
||||
public AuthenticationHandlerFactoryTests()
|
||||
{
|
||||
_app = new Mock<IApplicationBuilder>();
|
||||
_creator = new Mock<IAuthenticationHandlerCreator>();
|
||||
_authenticationProviderFactory = new AuthenticationProviderFactory(_creator.Object);
|
||||
_authenticationHandlerFactory = new AuthenticationHandlerFactory(_creator.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_identity_server_access_token_provider()
|
||||
public void should_return_identity_server_access_token_handler()
|
||||
{
|
||||
this.Given(x => x.GivenTheProviderIs("IdentityServer.AccessToken"))
|
||||
.And(x => x.GivenTheCreatorReturns())
|
||||
@ -72,7 +72,7 @@ namespace Ocelot.UnitTests.Authentication
|
||||
|
||||
private void WhenIGetFromTheFactory()
|
||||
{
|
||||
_result = _authenticationProviderFactory.Get(_provider, _app.Object);
|
||||
_result = _authenticationHandlerFactory.Get(_provider, _app.Object);
|
||||
}
|
||||
|
||||
private void ThenTheHandlerIsReturned(string expected)
|
@ -22,7 +22,7 @@ namespace Ocelot.UnitTests.Middleware
|
||||
public class AuthenticationMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IAuthenticationProviderFactory> _authFactory;
|
||||
private readonly Mock<IAuthenticationHandlerFactory> _authFactory;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
private readonly HttpClient _client;
|
||||
@ -33,7 +33,7 @@ namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_authFactory = new Mock<IAuthenticationProviderFactory>();
|
||||
_authFactory = new Mock<IAuthenticationHandlerFactory>();
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user