Added tests for identity server reference tokens, general refactoring and come config validation

This commit is contained in:
TomPallister
2016-10-16 20:28:23 +01:00
parent 7289cd803b
commit ce84ad4fc2
26 changed files with 565 additions and 150 deletions

View File

@@ -1,6 +1,8 @@
using IdentityServer4.AccessTokenValidation;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Responses;
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
namespace Ocelot.Library.Infrastructure.Authentication
{
@@ -9,17 +11,18 @@ namespace Ocelot.Library.Infrastructure.Authentication
/// </summary>
public class AuthenticationHandlerCreator : IAuthenticationHandlerCreator
{
public Response<RequestDelegate> CreateIdentityServerAuthenticationHandler(IApplicationBuilder app)
public Response<RequestDelegate> CreateIdentityServerAuthenticationHandler(IApplicationBuilder app, AuthenticationOptions authOptions)
{
var builder = app.New();
builder.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
//todo sort these options out
Authority = "http://localhost:51888",
ScopeName = "api",
RequireHttpsMetadata = false
Authority = authOptions.ProviderRootUrl,
ScopeName = authOptions.ScopeName,
RequireHttpsMetadata = authOptions.RequireHttps,
AdditionalScopes = authOptions.AdditionalScopes,
SupportedTokens = SupportedTokens.Both,
ScopeSecret = authOptions.ScopeSecret
});
builder.UseMvc();

View File

@@ -2,6 +2,7 @@ using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
namespace Ocelot.Library.Infrastructure.Authentication
{
@@ -14,18 +15,18 @@ namespace Ocelot.Library.Infrastructure.Authentication
_creator = creator;
}
public Response<AuthenticationHandler> Get(string provider, IApplicationBuilder app)
public Response<AuthenticationHandler> Get(IApplicationBuilder app, AuthenticationOptions authOptions)
{
var handler = _creator.CreateIdentityServerAuthenticationHandler(app);
var handler = _creator.CreateIdentityServerAuthenticationHandler(app, authOptions);
if (!handler.IsError)
{
return new OkResponse<AuthenticationHandler>(new AuthenticationHandler(provider, handler.Data));
return new OkResponse<AuthenticationHandler>(new AuthenticationHandler(authOptions.Provider, handler.Data));
}
return new ErrorResponse<AuthenticationHandler>(new List<Error>
{
new UnableToCreateAuthenticationHandlerError($"Unable to create authentication handler for {provider}")
new UnableToCreateAuthenticationHandlerError($"Unable to create authentication handler for {authOptions.Provider}")
});
}
}

View File

@@ -1,11 +1,12 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Responses;
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
namespace Ocelot.Library.Infrastructure.Authentication
{
public interface IAuthenticationHandlerCreator
{
Response<RequestDelegate> CreateIdentityServerAuthenticationHandler(IApplicationBuilder app);
Response<RequestDelegate> CreateIdentityServerAuthenticationHandler(IApplicationBuilder app, AuthenticationOptions authOptions);
}
}

View File

@@ -1,10 +1,11 @@
using Microsoft.AspNetCore.Builder;
using Ocelot.Library.Infrastructure.Responses;
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
namespace Ocelot.Library.Infrastructure.Authentication
{
public interface IAuthenticationHandlerFactory
{
Response<AuthenticationHandler> Get(string provider, IApplicationBuilder app);
Response<AuthenticationHandler> Get(IApplicationBuilder app, AuthenticationOptions authOptions);
}
}

View File

@@ -0,0 +1,7 @@
namespace Ocelot.Library.Infrastructure.Authentication
{
public enum SupportAuthenticationProviders
{
IdentityServer
}
}