Skip to content

Commit

Permalink
Rename IEndpointResultGenerator and derived types
Browse files Browse the repository at this point in the history
  • Loading branch information
josephdecock committed Oct 27, 2023
1 parent be9ce62 commit ff463c7
Show file tree
Hide file tree
Showing 31 changed files with 126 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,36 @@ public static IIdentityServerBuilder AddDefaultEndpoints(this IIdentityServerBui
builder.AddEndpoint<TokenEndpoint>(EndpointNames.Token, ProtocolRoutePaths.Token.EnsureLeadingSlash());
builder.AddEndpoint<UserInfoEndpoint>(EndpointNames.UserInfo, ProtocolRoutePaths.UserInfo.EnsureLeadingSlash());

builder.AddEndpointResultGenerator<AuthorizeInteractionPageResult, AuthorizeInteractionPageResultGenerator>();
builder.AddEndpointResultGenerator<AuthorizeResult, AuthorizeResultGenerator>();
builder.AddEndpointResultGenerator<BackchannelAuthenticationResult, BackchannelAuthenticationResultGenerator>();
builder.AddEndpointResultGenerator<BadRequestResult, BadRequestResultGenerator>();
builder.AddEndpointResultGenerator<CheckSessionResult, CheckSessionResultGenerator>();
builder.AddEndpointResultGenerator<DeviceAuthorizationResult, DeviceAuthorizationResultGenerator>();
builder.AddEndpointResultGenerator<DiscoveryDocumentResult, DiscoveryDocumentResultGenerator>();
builder.AddEndpointResultGenerator<EndSessionCallbackResult, EndSessionCallbackResultGenerator>();
builder.AddEndpointResultGenerator<EndSessionResult, EndSessionResultGenerator>();
builder.AddEndpointResultGenerator<IntrospectionResult, IntrospectionResultGenerator>();
builder.AddEndpointResultGenerator<JsonWebKeysResult, JsonWebKeysResultGenerator>();
builder.AddEndpointResultGenerator<ProtectedResourceErrorResult, ProtectedResourceErrorResultGenerator>();
builder.AddEndpointResultGenerator<PushedAuthorizationResult, PushedAuthorizationResultGenerator>();
builder.AddEndpointResultGenerator<PushedAuthorizationErrorResult, PushedAuthorizationErrorResultGenerator>();
builder.AddEndpointResultGenerator<StatusCodeResult, StatusCodeResultGenerator>();
builder.AddEndpointResultGenerator<TokenErrorResult, TokenErrorResultGenerator>();
builder.AddEndpointResultGenerator<TokenResult, TokenResultGenerator>();
builder.AddEndpointResultGenerator<TokenRevocationErrorResult, TokenRevocationErrorResultGenerator>();
builder.AddEndpointResultGenerator<UserInfoResult, UserInfoResultGenerator>();
builder.AddHttpWriter<AuthorizeInteractionPageResult, AuthorizeInteractionPageHttpWriter>();
builder.AddHttpWriter<AuthorizeResult, AuthorizeHttpWriter>();
builder.AddHttpWriter<BackchannelAuthenticationResult, BackchannelAuthenticationHttpWriter>();
builder.AddHttpWriter<BadRequestResult, BadRequestHttpWriter>();
builder.AddHttpWriter<CheckSessionResult, CheckSessionHttpWriter>();
builder.AddHttpWriter<DeviceAuthorizationResult, DeviceAuthorizationHttpWriter>();
builder.AddHttpWriter<DiscoveryDocumentResult, DiscoveryDocumentHttpWriter>();
builder.AddHttpWriter<EndSessionCallbackResult, EndSessionCallbackHttpWriter>();
builder.AddHttpWriter<EndSessionResult, EndSessionHttpWriter>();
builder.AddHttpWriter<IntrospectionResult, IntrospectionHttpWriter>();
builder.AddHttpWriter<JsonWebKeysResult, JsonWebKeysHttpWriter>();
builder.AddHttpWriter<ProtectedResourceErrorResult, ProtectedResourceErrorHttpWriter>();
builder.AddHttpWriter<PushedAuthorizationResult, PushedAuthorizationHttpWriter>();
builder.AddHttpWriter<PushedAuthorizationErrorResult, PushedAuthorizationErrorHttpWriter>();
builder.AddHttpWriter<StatusCodeResult, StatusCodeHttpWriter>();
builder.AddHttpWriter<TokenErrorResult, TokenErrorHttpWriter>();
builder.AddHttpWriter<TokenResult, TokenHttpWriter>();
builder.AddHttpWriter<TokenRevocationErrorResult, TokenRevocationErrorHttpWriter>();
builder.AddHttpWriter<UserInfoResult, UserInfoHttpWriter>();

return builder;
}

/// <summary>
/// Adds the endpoint.
/// Adds an endpoint.
/// </summary>
/// <typeparam name="TEndpoint"></typeparam>
/// <param name="builder">The builder.</param>
/// <param name="name">The name.</param>
/// <param name="path">The path.</param>
/// <returns></returns>
public static IIdentityServerBuilder AddEndpoint<TEndpoint>(this IIdentityServerBuilder builder, string name, PathString path)
where TEndpoint : class, IEndpointHandler
{
Expand All @@ -166,21 +165,20 @@ public static IIdentityServerBuilder AddEndpoint<TEndpoint>(this IIdentityServer
}

/// <summary>
/// Adds the endpoint.
/// Adds an <see cref="IHttpResponseWriter{T}"/> for an <see cref="IEndpointResult"/>.
/// </summary>
public static IIdentityServerBuilder AddEndpointResultGenerator<TResult, TResultGenerator>(this IIdentityServerBuilder builder)
public static IIdentityServerBuilder AddHttpWriter<TResult, TWriter>(this IIdentityServerBuilder builder)
where TResult : class, IEndpointResult
where TResultGenerator : class, Duende.IdentityServer.Hosting.IEndpointResultGenerator<TResult>
where TWriter : class, IHttpResponseWriter<TResult>
{
builder.Services.AddTransient<Duende.IdentityServer.Hosting.IEndpointResultGenerator<TResult>, TResultGenerator>();
builder.Services.AddTransient<IHttpResponseWriter<TResult>, TWriter>();
return builder;
}

/// <summary>
/// Adds the core services.
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns></returns>
public static IIdentityServerBuilder AddCoreServices(this IIdentityServerBuilder builder)
{
builder.Services.AddTransient<IServerUrls, DefaultServerUrls>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public AuthorizeInteractionPageResult(ValidatedAuthorizeRequest request, string
public string ReturnUrlParameterName { get; }
}

class AuthorizeInteractionPageResultGenerator : IEndpointResultGenerator<AuthorizeInteractionPageResult>
class AuthorizeInteractionPageHttpWriter : IHttpResponseWriter<AuthorizeInteractionPageResult>
{
private readonly IServerUrls _urls;
private readonly IAuthorizationParametersMessageStore _authorizationParametersMessageStore;

/// <summary>
/// Initializes a new instance of the <see cref="AuthorizeInteractionPageResult"/> class.
/// </summary>
public AuthorizeInteractionPageResultGenerator(
public AuthorizeInteractionPageHttpWriter(
IServerUrls urls,
IAuthorizationParametersMessageStore authorizationParametersMessageStore = null)
{
Expand All @@ -70,7 +70,7 @@ public AuthorizeInteractionPageResultGenerator(
}

/// <inheritdoc/>
public async Task ExecuteAsync(AuthorizeInteractionPageResult result, HttpContext context)
public async Task WriteHttpResponse(AuthorizeInteractionPageResult result, HttpContext context)
{
var returnUrl = _urls.BasePath.EnsureTrailingSlash() + ProtocolRoutePaths.AuthorizeCallback;

Expand Down
6 changes: 3 additions & 3 deletions src/IdentityServer/Endpoints/Results/AuthorizeResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public AuthorizeResult(AuthorizeResponse response)
}
}

internal class AuthorizeResultGenerator : IEndpointResultGenerator<AuthorizeResult>
internal class AuthorizeHttpWriter : IHttpResponseWriter<AuthorizeResult>
{
public AuthorizeResultGenerator(
public AuthorizeHttpWriter(
IdentityServerOptions options,
IUserSession userSession,
IPushedAuthorizationService pushedAuthorizationService,
Expand All @@ -63,7 +63,7 @@ public AuthorizeResultGenerator(
private readonly IServerUrls _urls;
private readonly IClock _clock;

public async Task ExecuteAsync(AuthorizeResult result, HttpContext context)
public async Task WriteHttpResponse(AuthorizeResult result, HttpContext context)
{
await ConsumePushedAuthorizationRequest(result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public BackchannelAuthenticationResult(BackchannelAuthenticationResponse respons
}
}

internal class BackchannelAuthenticationResultGenerator : IEndpointResultGenerator<BackchannelAuthenticationResult>
internal class BackchannelAuthenticationHttpWriter : IHttpResponseWriter<BackchannelAuthenticationResult>
{
public async Task ExecuteAsync(BackchannelAuthenticationResult result, HttpContext context)
public async Task WriteHttpResponse(BackchannelAuthenticationResult result, HttpContext context)
{
context.Response.SetNoCache();

Expand Down
4 changes: 2 additions & 2 deletions src/IdentityServer/Endpoints/Results/BadRequestResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public BadRequestResult(string error = null, string errorDescription = null)
}
}

internal class BadRequestResultGenerator : IEndpointResultGenerator<BadRequestResult>
internal class BadRequestHttpWriter : IHttpResponseWriter<BadRequestResult>
{
public async Task ExecuteAsync(BadRequestResult result, HttpContext context)
public async Task WriteHttpResponse(BadRequestResult result, HttpContext context)
{
context.Response.StatusCode = 400;
context.Response.SetNoCache();
Expand Down
6 changes: 3 additions & 3 deletions src/IdentityServer/Endpoints/Results/CheckSessionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class CheckSessionResult : EndpointResult<CheckSessionResult>
}


internal class CheckSessionResultGenerator : IEndpointResultGenerator<CheckSessionResult>
internal class CheckSessionHttpWriter : IHttpResponseWriter<CheckSessionResult>
{
public CheckSessionResultGenerator(IdentityServerOptions options)
public CheckSessionHttpWriter(IdentityServerOptions options)
{
_options = options;
}
Expand All @@ -30,7 +30,7 @@ public CheckSessionResultGenerator(IdentityServerOptions options)
private static readonly object Lock = new object();
private static volatile string LastCheckSessionCookieName;

public async Task ExecuteAsync(CheckSessionResult result, HttpContext context)
public async Task WriteHttpResponse(CheckSessionResult result, HttpContext context)
{
AddCspHeaders(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public DeviceAuthorizationResult(DeviceAuthorizationResponse response)
}
}

internal class DeviceAuthorizationResultGenerator : IEndpointResultGenerator<DeviceAuthorizationResult>
internal class DeviceAuthorizationHttpWriter : IHttpResponseWriter<DeviceAuthorizationResult>
{
public async Task ExecuteAsync(DeviceAuthorizationResult result, HttpContext context)
public async Task WriteHttpResponse(DeviceAuthorizationResult result, HttpContext context)
{
context.Response.SetNoCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public DiscoveryDocumentResult(Dictionary<string, object> entries, int? maxAge =
}
}

class DiscoveryDocumentResultGenerator : IEndpointResultGenerator<DiscoveryDocumentResult>
class DiscoveryDocumentHttpWriter : IHttpResponseWriter<DiscoveryDocumentResult>
{
/// <inheritdoc/>
public Task ExecuteAsync(DiscoveryDocumentResult result, HttpContext context)
public Task WriteHttpResponse(DiscoveryDocumentResult result, HttpContext context)
{
if (result.MaxAge.HasValue && result.MaxAge.Value >= 0)
{
Expand Down
12 changes: 7 additions & 5 deletions src/IdentityServer/Endpoints/Results/EndPointResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
namespace Duende.IdentityServer.Endpoints.Results;

/// <summary>
/// Provides the base implementation of IEndpointResult that invokes the corresponding IEndpointResultGenerator<typeparamref name="T"/>.
/// Provides the base implementation of <see cref="IEndpointResult"/> that
/// invokes the corresponding <see cref="IHttpResponseWriter{T}"/> to write the
/// result as an http response.
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class EndpointResult<T> : IEndpointResult
Expand All @@ -20,16 +22,16 @@ public abstract class EndpointResult<T> : IEndpointResult
/// <inheritdoc/>
public async Task ExecuteAsync(HttpContext context)
{
var generator = context.RequestServices.GetService<IEndpointResultGenerator<T>>();
if (generator != null)
var writer = context.RequestServices.GetService<IHttpResponseWriter<T>>();
if (writer != null)
{
T target = this as T;
if (target == null)
{
throw new Exception($"Type paramter {typeof(T)} must be the class derived from 'EndPointResult<T>'.");
throw new Exception($"Type parameter {typeof(T)} must be the class derived from 'EndpointResult<T>'.");
}

await generator.ExecuteAsync(target, context);
await writer.WriteHttpResponse(target, context);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ public EndSessionCallbackResult(EndSessionCallbackValidationResult result)
}
}

class EndSessionCallbackResultGenerator : IEndpointResultGenerator<EndSessionCallbackResult>
class EndSessionCallbackHttpWriter : IHttpResponseWriter<EndSessionCallbackResult>
{
public EndSessionCallbackResultGenerator(IdentityServerOptions options)
public EndSessionCallbackHttpWriter(IdentityServerOptions options)
{
_options = options;
}

private IdentityServerOptions _options;

public async Task ExecuteAsync(EndSessionCallbackResult result, HttpContext context)
public async Task WriteHttpResponse(EndSessionCallbackResult result, HttpContext context)
{
if (result.Result.IsError)
{
Expand Down
6 changes: 3 additions & 3 deletions src/IdentityServer/Endpoints/Results/EndSessionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public EndSessionResult(EndSessionValidationResult result)
}


class EndSessionResultGenerator : IEndpointResultGenerator<EndSessionResult>
class EndSessionHttpWriter : IHttpResponseWriter<EndSessionResult>
{
public EndSessionResultGenerator(
public EndSessionHttpWriter(
IdentityServerOptions options,
IClock clock,
IServerUrls urls,
Expand All @@ -57,7 +57,7 @@ public EndSessionResultGenerator(
private IServerUrls _urls;
private IMessageStore<LogoutMessage> _logoutMessageStore;

public async Task ExecuteAsync(EndSessionResult result, HttpContext context)
public async Task WriteHttpResponse(EndSessionResult result, HttpContext context)
{
var validatedRequest = result.Result.IsError ? null : result.Result.ValidatedRequest;

Expand Down
4 changes: 2 additions & 2 deletions src/IdentityServer/Endpoints/Results/IntrospectionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public IntrospectionResult(Dictionary<string, object> entries)
}


class IntrospectionResultGenerator : IEndpointResultGenerator<IntrospectionResult>
class IntrospectionHttpWriter : IHttpResponseWriter<IntrospectionResult>
{
public Task ExecuteAsync(IntrospectionResult result, HttpContext context)
public Task WriteHttpResponse(IntrospectionResult result, HttpContext context)
{
context.Response.SetNoCache();

Expand Down
4 changes: 2 additions & 2 deletions src/IdentityServer/Endpoints/Results/JsonWebKeysResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public JsonWebKeysResult(IEnumerable<JsonWebKey> webKeys, int? maxAge)
}
}

class JsonWebKeysResultGenerator : IEndpointResultGenerator<JsonWebKeysResult>
class JsonWebKeysHttpWriter : IHttpResponseWriter<JsonWebKeysResult>
{
public Task ExecuteAsync(JsonWebKeysResult result, HttpContext context)
public Task WriteHttpResponse(JsonWebKeysResult result, HttpContext context)
{
if (result.MaxAge.HasValue && result.MaxAge.Value >= 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public ProtectedResourceErrorResult(string error, string errorDescription = null
}
}

internal class ProtectedResourceErrorResultGenerator : IEndpointResultGenerator<ProtectedResourceErrorResult>
internal class ProtectedResourceErrorHttpWriter : IHttpResponseWriter<ProtectedResourceErrorResult>
{
public Task ExecuteAsync(ProtectedResourceErrorResult result, HttpContext context)
public Task WriteHttpResponse(ProtectedResourceErrorResult result, HttpContext context)
{
context.Response.StatusCode = 401;
context.Response.SetNoCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public PushedAuthorizationErrorResult(PushedAuthorizationFailure response)
}
}

internal class PushedAuthorizationErrorResultGenerator : IEndpointResultGenerator<PushedAuthorizationErrorResult>
internal class PushedAuthorizationErrorHttpWriter : IHttpResponseWriter<PushedAuthorizationErrorResult>
{
public async Task ExecuteAsync(PushedAuthorizationErrorResult result, HttpContext context)
public async Task WriteHttpResponse(PushedAuthorizationErrorResult result, HttpContext context)
{
context.Response.SetNoCache();
context.Response.StatusCode = (int) HttpStatusCode.BadRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public PushedAuthorizationResult(PushedAuthorizationSuccess response)
}
}

internal class PushedAuthorizationResultGenerator : IEndpointResultGenerator<PushedAuthorizationResult>
internal class PushedAuthorizationHttpWriter : IHttpResponseWriter<PushedAuthorizationResult>
{
public async Task ExecuteAsync(PushedAuthorizationResult result, HttpContext context)
public async Task WriteHttpResponse(PushedAuthorizationResult result, HttpContext context)
{
context.Response.SetNoCache();
context.Response.StatusCode = (int) HttpStatusCode.Created;
Expand Down
4 changes: 2 additions & 2 deletions src/IdentityServer/Endpoints/Results/StatusCodeResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public StatusCodeResult(int statusCode)
}
}

class StatusCodeResultGenerator : IEndpointResultGenerator<StatusCodeResult>
class StatusCodeHttpWriter : IHttpResponseWriter<StatusCodeResult>
{
public Task ExecuteAsync(StatusCodeResult result, HttpContext context)
public Task WriteHttpResponse(StatusCodeResult result, HttpContext context)
{
context.Response.StatusCode = result.StatusCode;

Expand Down
4 changes: 2 additions & 2 deletions src/IdentityServer/Endpoints/Results/TokenErrorResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public TokenErrorResult(TokenErrorResponse error)
}
}

internal class TokenErrorResultGenerator : IEndpointResultGenerator<TokenErrorResult>
internal class TokenErrorHttpWriter : IHttpResponseWriter<TokenErrorResult>
{
public async Task ExecuteAsync(TokenErrorResult result, HttpContext context)
public async Task WriteHttpResponse(TokenErrorResult result, HttpContext context)
{
context.Response.StatusCode = 400;
context.Response.SetNoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/IdentityServer/Endpoints/Results/TokenResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public TokenResult(TokenResponse response)
}
}

internal class TokenResultGenerator : IEndpointResultGenerator<TokenResult>
internal class TokenHttpWriter : IHttpResponseWriter<TokenResult>
{
public async Task ExecuteAsync(TokenResult result, HttpContext context)
public async Task WriteHttpResponse(TokenResult result, HttpContext context)
{
context.Response.SetNoCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public TokenRevocationErrorResult(string error)
}
}

class TokenRevocationErrorResultGenerator : IEndpointResultGenerator<TokenRevocationErrorResult>
class TokenRevocationErrorHttpWriter : IHttpResponseWriter<TokenRevocationErrorResult>
{
public Task ExecuteAsync(TokenRevocationErrorResult result, HttpContext context)
public Task WriteHttpResponse(TokenRevocationErrorResult result, HttpContext context)
{
context.Response.StatusCode = (int) HttpStatusCode.BadRequest;
return context.Response.WriteJsonAsync(new { error = result.Error });
Expand Down
4 changes: 2 additions & 2 deletions src/IdentityServer/Endpoints/Results/UserInfoResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public UserInfoResult(Dictionary<string, object> claims)
}
}

internal class UserInfoResultGenerator : IEndpointResultGenerator<UserInfoResult>
internal class UserInfoHttpWriter : IHttpResponseWriter<UserInfoResult>
{
public async Task ExecuteAsync(UserInfoResult result, HttpContext context)
public async Task WriteHttpResponse(UserInfoResult result, HttpContext context)
{
context.Response.SetNoCache();
await context.Response.WriteJsonAsync(result.Claims);
Expand Down
Loading

0 comments on commit ff463c7

Please sign in to comment.