From ff463c707d18b121ed1777b5573536ade4994987 Mon Sep 17 00:00:00 2001 From: Joe DeCock Date: Fri, 27 Oct 2023 14:37:59 -0500 Subject: [PATCH] Rename IEndpointResultGenerator and derived types --- .../BuilderExtensions/Core.cs | 50 +++++++++---------- .../Results/AuthorizeInteractionPageResult.cs | 6 +-- .../Endpoints/Results/AuthorizeResult.cs | 6 +-- .../BackchannelAuthenticationResult.cs | 4 +- .../Endpoints/Results/BadRequestResult.cs | 4 +- .../Endpoints/Results/CheckSessionResult.cs | 6 +-- .../Results/DeviceAuthorizationResult.cs | 4 +- .../Results/DiscoveryDocumentResult.cs | 4 +- .../Endpoints/Results/EndPointResult.cs | 12 +++-- .../Results/EndSessionCallbackResult.cs | 6 +-- .../Endpoints/Results/EndSessionResult.cs | 6 +-- .../Endpoints/Results/IntrospectionResult.cs | 4 +- .../Endpoints/Results/JsonWebKeysResult.cs | 4 +- .../Results/ProtectedResourceErrorResult.cs | 4 +- .../Results/PushedAuthorizationErrorResult.cs | 4 +- .../Results/PushedAuthorizationResult.cs | 4 +- .../Endpoints/Results/StatusCodeResult.cs | 4 +- .../Endpoints/Results/TokenErrorResult.cs | 4 +- .../Endpoints/Results/TokenResult.cs | 4 +- .../Results/TokenRevocationErrorResult.cs | 4 +- .../Endpoints/Results/UserInfoResult.cs | 4 +- src/IdentityServer/Hosting/IEndpointResult.cs | 7 +-- src/IdentityServer/Hosting/IEndpointRouter.cs | 10 ++-- ...ultGenerator.cs => IHttpResponseWriter.cs} | 7 +-- .../IPushedAuthorizationSerializer.cs | 3 +- .../Services/IPushedAuthorizationService.cs | 3 +- .../EndSessionCallbackResultTests.cs | 8 +-- .../Endpoints/Results/AuthorizeResultTests.cs | 24 ++++----- .../Results/CheckSessionResultTests.cs | 12 ++--- .../Results/EndSessionCallbackResultTests.cs | 12 ++--- .../Results/EndSessionResultTests.cs | 10 ++-- 31 files changed, 126 insertions(+), 118 deletions(-) rename src/IdentityServer/Hosting/{IEndpointResultGenerator.cs => IHttpResponseWriter.cs} (63%) diff --git a/src/IdentityServer/Configuration/DependencyInjection/BuilderExtensions/Core.cs b/src/IdentityServer/Configuration/DependencyInjection/BuilderExtensions/Core.cs index d8e1121d1..754ee2214 100644 --- a/src/IdentityServer/Configuration/DependencyInjection/BuilderExtensions/Core.cs +++ b/src/IdentityServer/Configuration/DependencyInjection/BuilderExtensions/Core.cs @@ -125,37 +125,36 @@ public static IIdentityServerBuilder AddDefaultEndpoints(this IIdentityServerBui builder.AddEndpoint(EndpointNames.Token, ProtocolRoutePaths.Token.EnsureLeadingSlash()); builder.AddEndpoint(EndpointNames.UserInfo, ProtocolRoutePaths.UserInfo.EnsureLeadingSlash()); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); - builder.AddEndpointResultGenerator(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); + builder.AddHttpWriter(); return builder; } /// - /// Adds the endpoint. + /// Adds an endpoint. /// /// /// The builder. /// The name. /// The path. - /// public static IIdentityServerBuilder AddEndpoint(this IIdentityServerBuilder builder, string name, PathString path) where TEndpoint : class, IEndpointHandler { @@ -166,13 +165,13 @@ public static IIdentityServerBuilder AddEndpoint(this IIdentityServer } /// - /// Adds the endpoint. + /// Adds an for an . /// - public static IIdentityServerBuilder AddEndpointResultGenerator(this IIdentityServerBuilder builder) + public static IIdentityServerBuilder AddHttpWriter(this IIdentityServerBuilder builder) where TResult : class, IEndpointResult - where TResultGenerator : class, Duende.IdentityServer.Hosting.IEndpointResultGenerator + where TWriter : class, IHttpResponseWriter { - builder.Services.AddTransient, TResultGenerator>(); + builder.Services.AddTransient, TWriter>(); return builder; } @@ -180,7 +179,6 @@ public static IIdentityServerBuilder AddEndpointResultGenerator /// The builder. - /// public static IIdentityServerBuilder AddCoreServices(this IIdentityServerBuilder builder) { builder.Services.AddTransient(); diff --git a/src/IdentityServer/Endpoints/Results/AuthorizeInteractionPageResult.cs b/src/IdentityServer/Endpoints/Results/AuthorizeInteractionPageResult.cs index 3c9178c2b..429c995a3 100644 --- a/src/IdentityServer/Endpoints/Results/AuthorizeInteractionPageResult.cs +++ b/src/IdentityServer/Endpoints/Results/AuthorizeInteractionPageResult.cs @@ -53,7 +53,7 @@ public AuthorizeInteractionPageResult(ValidatedAuthorizeRequest request, string public string ReturnUrlParameterName { get; } } -class AuthorizeInteractionPageResultGenerator : IEndpointResultGenerator +class AuthorizeInteractionPageHttpWriter : IHttpResponseWriter { private readonly IServerUrls _urls; private readonly IAuthorizationParametersMessageStore _authorizationParametersMessageStore; @@ -61,7 +61,7 @@ class AuthorizeInteractionPageResultGenerator : IEndpointResultGenerator /// Initializes a new instance of the class. /// - public AuthorizeInteractionPageResultGenerator( + public AuthorizeInteractionPageHttpWriter( IServerUrls urls, IAuthorizationParametersMessageStore authorizationParametersMessageStore = null) { @@ -70,7 +70,7 @@ public AuthorizeInteractionPageResultGenerator( } /// - public async Task ExecuteAsync(AuthorizeInteractionPageResult result, HttpContext context) + public async Task WriteHttpResponse(AuthorizeInteractionPageResult result, HttpContext context) { var returnUrl = _urls.BasePath.EnsureTrailingSlash() + ProtocolRoutePaths.AuthorizeCallback; diff --git a/src/IdentityServer/Endpoints/Results/AuthorizeResult.cs b/src/IdentityServer/Endpoints/Results/AuthorizeResult.cs index 0441a0fc7..698e361a9 100644 --- a/src/IdentityServer/Endpoints/Results/AuthorizeResult.cs +++ b/src/IdentityServer/Endpoints/Results/AuthorizeResult.cs @@ -38,9 +38,9 @@ public AuthorizeResult(AuthorizeResponse response) } } -internal class AuthorizeResultGenerator : IEndpointResultGenerator +internal class AuthorizeHttpWriter : IHttpResponseWriter { - public AuthorizeResultGenerator( + public AuthorizeHttpWriter( IdentityServerOptions options, IUserSession userSession, IPushedAuthorizationService pushedAuthorizationService, @@ -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); diff --git a/src/IdentityServer/Endpoints/Results/BackchannelAuthenticationResult.cs b/src/IdentityServer/Endpoints/Results/BackchannelAuthenticationResult.cs index 467e74a1b..f77039faa 100644 --- a/src/IdentityServer/Endpoints/Results/BackchannelAuthenticationResult.cs +++ b/src/IdentityServer/Endpoints/Results/BackchannelAuthenticationResult.cs @@ -33,9 +33,9 @@ public BackchannelAuthenticationResult(BackchannelAuthenticationResponse respons } } -internal class BackchannelAuthenticationResultGenerator : IEndpointResultGenerator +internal class BackchannelAuthenticationHttpWriter : IHttpResponseWriter { - public async Task ExecuteAsync(BackchannelAuthenticationResult result, HttpContext context) + public async Task WriteHttpResponse(BackchannelAuthenticationResult result, HttpContext context) { context.Response.SetNoCache(); diff --git a/src/IdentityServer/Endpoints/Results/BadRequestResult.cs b/src/IdentityServer/Endpoints/Results/BadRequestResult.cs index 42f1f772c..47e47abc4 100644 --- a/src/IdentityServer/Endpoints/Results/BadRequestResult.cs +++ b/src/IdentityServer/Endpoints/Results/BadRequestResult.cs @@ -35,9 +35,9 @@ public BadRequestResult(string error = null, string errorDescription = null) } } -internal class BadRequestResultGenerator : IEndpointResultGenerator +internal class BadRequestHttpWriter : IHttpResponseWriter { - public async Task ExecuteAsync(BadRequestResult result, HttpContext context) + public async Task WriteHttpResponse(BadRequestResult result, HttpContext context) { context.Response.StatusCode = 400; context.Response.SetNoCache(); diff --git a/src/IdentityServer/Endpoints/Results/CheckSessionResult.cs b/src/IdentityServer/Endpoints/Results/CheckSessionResult.cs index be1c492b3..abd844f9a 100644 --- a/src/IdentityServer/Endpoints/Results/CheckSessionResult.cs +++ b/src/IdentityServer/Endpoints/Results/CheckSessionResult.cs @@ -18,9 +18,9 @@ public class CheckSessionResult : EndpointResult } -internal class CheckSessionResultGenerator : IEndpointResultGenerator +internal class CheckSessionHttpWriter : IHttpResponseWriter { - public CheckSessionResultGenerator(IdentityServerOptions options) + public CheckSessionHttpWriter(IdentityServerOptions options) { _options = options; } @@ -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); diff --git a/src/IdentityServer/Endpoints/Results/DeviceAuthorizationResult.cs b/src/IdentityServer/Endpoints/Results/DeviceAuthorizationResult.cs index bad114a44..70792eda3 100644 --- a/src/IdentityServer/Endpoints/Results/DeviceAuthorizationResult.cs +++ b/src/IdentityServer/Endpoints/Results/DeviceAuthorizationResult.cs @@ -32,9 +32,9 @@ public DeviceAuthorizationResult(DeviceAuthorizationResponse response) } } -internal class DeviceAuthorizationResultGenerator : IEndpointResultGenerator +internal class DeviceAuthorizationHttpWriter : IHttpResponseWriter { - public async Task ExecuteAsync(DeviceAuthorizationResult result, HttpContext context) + public async Task WriteHttpResponse(DeviceAuthorizationResult result, HttpContext context) { context.Response.SetNoCache(); diff --git a/src/IdentityServer/Endpoints/Results/DiscoveryDocumentResult.cs b/src/IdentityServer/Endpoints/Results/DiscoveryDocumentResult.cs index 0d5b5d54f..9ccaa8276 100644 --- a/src/IdentityServer/Endpoints/Results/DiscoveryDocumentResult.cs +++ b/src/IdentityServer/Endpoints/Results/DiscoveryDocumentResult.cs @@ -46,10 +46,10 @@ public DiscoveryDocumentResult(Dictionary entries, int? maxAge = } } -class DiscoveryDocumentResultGenerator : IEndpointResultGenerator +class DiscoveryDocumentHttpWriter : IHttpResponseWriter { /// - public Task ExecuteAsync(DiscoveryDocumentResult result, HttpContext context) + public Task WriteHttpResponse(DiscoveryDocumentResult result, HttpContext context) { if (result.MaxAge.HasValue && result.MaxAge.Value >= 0) { diff --git a/src/IdentityServer/Endpoints/Results/EndPointResult.cs b/src/IdentityServer/Endpoints/Results/EndPointResult.cs index 0b5195ea4..59c109998 100644 --- a/src/IdentityServer/Endpoints/Results/EndPointResult.cs +++ b/src/IdentityServer/Endpoints/Results/EndPointResult.cs @@ -11,7 +11,9 @@ namespace Duende.IdentityServer.Endpoints.Results; /// -/// Provides the base implementation of IEndpointResult that invokes the corresponding IEndpointResultGenerator. +/// Provides the base implementation of that +/// invokes the corresponding to write the +/// result as an http response. /// /// public abstract class EndpointResult : IEndpointResult @@ -20,16 +22,16 @@ public abstract class EndpointResult : IEndpointResult /// public async Task ExecuteAsync(HttpContext context) { - var generator = context.RequestServices.GetService>(); - if (generator != null) + var writer = context.RequestServices.GetService>(); + 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'."); + throw new Exception($"Type parameter {typeof(T)} must be the class derived from 'EndpointResult'."); } - await generator.ExecuteAsync(target, context); + await writer.WriteHttpResponse(target, context); } else { diff --git a/src/IdentityServer/Endpoints/Results/EndSessionCallbackResult.cs b/src/IdentityServer/Endpoints/Results/EndSessionCallbackResult.cs index d4c32ae0e..3b61eee6e 100644 --- a/src/IdentityServer/Endpoints/Results/EndSessionCallbackResult.cs +++ b/src/IdentityServer/Endpoints/Results/EndSessionCallbackResult.cs @@ -37,16 +37,16 @@ public EndSessionCallbackResult(EndSessionCallbackValidationResult result) } } -class EndSessionCallbackResultGenerator : IEndpointResultGenerator +class EndSessionCallbackHttpWriter : IHttpResponseWriter { - 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) { diff --git a/src/IdentityServer/Endpoints/Results/EndSessionResult.cs b/src/IdentityServer/Endpoints/Results/EndSessionResult.cs index e63cc8133..57f5af4e3 100644 --- a/src/IdentityServer/Endpoints/Results/EndSessionResult.cs +++ b/src/IdentityServer/Endpoints/Results/EndSessionResult.cs @@ -38,9 +38,9 @@ public EndSessionResult(EndSessionValidationResult result) } -class EndSessionResultGenerator : IEndpointResultGenerator +class EndSessionHttpWriter : IHttpResponseWriter { - public EndSessionResultGenerator( + public EndSessionHttpWriter( IdentityServerOptions options, IClock clock, IServerUrls urls, @@ -57,7 +57,7 @@ public EndSessionResultGenerator( private IServerUrls _urls; private IMessageStore _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; diff --git a/src/IdentityServer/Endpoints/Results/IntrospectionResult.cs b/src/IdentityServer/Endpoints/Results/IntrospectionResult.cs index bd2e74714..ae17d31ff 100644 --- a/src/IdentityServer/Endpoints/Results/IntrospectionResult.cs +++ b/src/IdentityServer/Endpoints/Results/IntrospectionResult.cs @@ -37,9 +37,9 @@ public IntrospectionResult(Dictionary entries) } -class IntrospectionResultGenerator : IEndpointResultGenerator +class IntrospectionHttpWriter : IHttpResponseWriter { - public Task ExecuteAsync(IntrospectionResult result, HttpContext context) + public Task WriteHttpResponse(IntrospectionResult result, HttpContext context) { context.Response.SetNoCache(); diff --git a/src/IdentityServer/Endpoints/Results/JsonWebKeysResult.cs b/src/IdentityServer/Endpoints/Results/JsonWebKeysResult.cs index 094a57e00..00d4e3464 100644 --- a/src/IdentityServer/Endpoints/Results/JsonWebKeysResult.cs +++ b/src/IdentityServer/Endpoints/Results/JsonWebKeysResult.cs @@ -46,9 +46,9 @@ public JsonWebKeysResult(IEnumerable webKeys, int? maxAge) } } -class JsonWebKeysResultGenerator : IEndpointResultGenerator +class JsonWebKeysHttpWriter : IHttpResponseWriter { - public Task ExecuteAsync(JsonWebKeysResult result, HttpContext context) + public Task WriteHttpResponse(JsonWebKeysResult result, HttpContext context) { if (result.MaxAge.HasValue && result.MaxAge.Value >= 0) { diff --git a/src/IdentityServer/Endpoints/Results/ProtectedResourceErrorResult.cs b/src/IdentityServer/Endpoints/Results/ProtectedResourceErrorResult.cs index f2d9cc821..25dd873d6 100644 --- a/src/IdentityServer/Endpoints/Results/ProtectedResourceErrorResult.cs +++ b/src/IdentityServer/Endpoints/Results/ProtectedResourceErrorResult.cs @@ -38,9 +38,9 @@ public ProtectedResourceErrorResult(string error, string errorDescription = null } } -internal class ProtectedResourceErrorResultGenerator : IEndpointResultGenerator +internal class ProtectedResourceErrorHttpWriter : IHttpResponseWriter { - public Task ExecuteAsync(ProtectedResourceErrorResult result, HttpContext context) + public Task WriteHttpResponse(ProtectedResourceErrorResult result, HttpContext context) { context.Response.StatusCode = 401; context.Response.SetNoCache(); diff --git a/src/IdentityServer/Endpoints/Results/PushedAuthorizationErrorResult.cs b/src/IdentityServer/Endpoints/Results/PushedAuthorizationErrorResult.cs index 5b38d81fd..77755419a 100644 --- a/src/IdentityServer/Endpoints/Results/PushedAuthorizationErrorResult.cs +++ b/src/IdentityServer/Endpoints/Results/PushedAuthorizationErrorResult.cs @@ -33,9 +33,9 @@ public PushedAuthorizationErrorResult(PushedAuthorizationFailure response) } } -internal class PushedAuthorizationErrorResultGenerator : IEndpointResultGenerator +internal class PushedAuthorizationErrorHttpWriter : IHttpResponseWriter { - 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; diff --git a/src/IdentityServer/Endpoints/Results/PushedAuthorizationResult.cs b/src/IdentityServer/Endpoints/Results/PushedAuthorizationResult.cs index cc6b87982..f1f5ec2de 100644 --- a/src/IdentityServer/Endpoints/Results/PushedAuthorizationResult.cs +++ b/src/IdentityServer/Endpoints/Results/PushedAuthorizationResult.cs @@ -33,9 +33,9 @@ public PushedAuthorizationResult(PushedAuthorizationSuccess response) } } -internal class PushedAuthorizationResultGenerator : IEndpointResultGenerator +internal class PushedAuthorizationHttpWriter : IHttpResponseWriter { - 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; diff --git a/src/IdentityServer/Endpoints/Results/StatusCodeResult.cs b/src/IdentityServer/Endpoints/Results/StatusCodeResult.cs index 69064b5af..4a54fcb78 100644 --- a/src/IdentityServer/Endpoints/Results/StatusCodeResult.cs +++ b/src/IdentityServer/Endpoints/Results/StatusCodeResult.cs @@ -42,9 +42,9 @@ public StatusCodeResult(int statusCode) } } -class StatusCodeResultGenerator : IEndpointResultGenerator +class StatusCodeHttpWriter : IHttpResponseWriter { - public Task ExecuteAsync(StatusCodeResult result, HttpContext context) + public Task WriteHttpResponse(StatusCodeResult result, HttpContext context) { context.Response.StatusCode = result.StatusCode; diff --git a/src/IdentityServer/Endpoints/Results/TokenErrorResult.cs b/src/IdentityServer/Endpoints/Results/TokenErrorResult.cs index 7f9243494..c5f2ea059 100644 --- a/src/IdentityServer/Endpoints/Results/TokenErrorResult.cs +++ b/src/IdentityServer/Endpoints/Results/TokenErrorResult.cs @@ -37,9 +37,9 @@ public TokenErrorResult(TokenErrorResponse error) } } -internal class TokenErrorResultGenerator : IEndpointResultGenerator +internal class TokenErrorHttpWriter : IHttpResponseWriter { - public async Task ExecuteAsync(TokenErrorResult result, HttpContext context) + public async Task WriteHttpResponse(TokenErrorResult result, HttpContext context) { context.Response.StatusCode = 400; context.Response.SetNoCache(); diff --git a/src/IdentityServer/Endpoints/Results/TokenResult.cs b/src/IdentityServer/Endpoints/Results/TokenResult.cs index eebd17102..19bf08cd9 100644 --- a/src/IdentityServer/Endpoints/Results/TokenResult.cs +++ b/src/IdentityServer/Endpoints/Results/TokenResult.cs @@ -35,9 +35,9 @@ public TokenResult(TokenResponse response) } } -internal class TokenResultGenerator : IEndpointResultGenerator +internal class TokenHttpWriter : IHttpResponseWriter { - public async Task ExecuteAsync(TokenResult result, HttpContext context) + public async Task WriteHttpResponse(TokenResult result, HttpContext context) { context.Response.SetNoCache(); diff --git a/src/IdentityServer/Endpoints/Results/TokenRevocationErrorResult.cs b/src/IdentityServer/Endpoints/Results/TokenRevocationErrorResult.cs index b0a2549cd..5afec89e7 100644 --- a/src/IdentityServer/Endpoints/Results/TokenRevocationErrorResult.cs +++ b/src/IdentityServer/Endpoints/Results/TokenRevocationErrorResult.cs @@ -35,9 +35,9 @@ public TokenRevocationErrorResult(string error) } } -class TokenRevocationErrorResultGenerator : IEndpointResultGenerator +class TokenRevocationErrorHttpWriter : IHttpResponseWriter { - 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 }); diff --git a/src/IdentityServer/Endpoints/Results/UserInfoResult.cs b/src/IdentityServer/Endpoints/Results/UserInfoResult.cs index a0b7a5b2b..be4b2561a 100644 --- a/src/IdentityServer/Endpoints/Results/UserInfoResult.cs +++ b/src/IdentityServer/Endpoints/Results/UserInfoResult.cs @@ -31,9 +31,9 @@ public UserInfoResult(Dictionary claims) } } -internal class UserInfoResultGenerator : IEndpointResultGenerator +internal class UserInfoHttpWriter : IHttpResponseWriter { - 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); diff --git a/src/IdentityServer/Hosting/IEndpointResult.cs b/src/IdentityServer/Hosting/IEndpointResult.cs index b74d213bc..30f30c276 100644 --- a/src/IdentityServer/Hosting/IEndpointResult.cs +++ b/src/IdentityServer/Hosting/IEndpointResult.cs @@ -8,15 +8,16 @@ namespace Duende.IdentityServer.Hosting; /// -/// Endpoint result +/// An is the object model that describes the +/// results that will returned by one of the protocol endpoints provided by +/// IdentityServer, and can be executed to produce an HTTP response. /// public interface IEndpointResult { /// - /// Executes the result. + /// Executes the result to write an http response. /// /// The HTTP context. - /// Task ExecuteAsync(HttpContext context); } diff --git a/src/IdentityServer/Hosting/IEndpointRouter.cs b/src/IdentityServer/Hosting/IEndpointRouter.cs index 1981bde69..74aea6ade 100644 --- a/src/IdentityServer/Hosting/IEndpointRouter.cs +++ b/src/IdentityServer/Hosting/IEndpointRouter.cs @@ -9,14 +9,18 @@ namespace Duende.IdentityServer.Hosting; /// -/// The endpoint router +/// The endpoint router is responsible for mapping incoming http requests onto +/// s, for the protocol endpoints that +/// IdentityServer supports. /// public interface IEndpointRouter { /// - /// Finds a matching endpoint. + /// Finds a matching for an incoming http + /// request. /// /// The HTTP context. - /// + /// The handler to process a protocol request, or null, if the + /// incoming http request is not a protocol request. IEndpointHandler? Find(HttpContext context); } diff --git a/src/IdentityServer/Hosting/IEndpointResultGenerator.cs b/src/IdentityServer/Hosting/IHttpResponseWriter.cs similarity index 63% rename from src/IdentityServer/Hosting/IEndpointResultGenerator.cs rename to src/IdentityServer/Hosting/IHttpResponseWriter.cs index dd7e2ac21..a1b7f54f4 100644 --- a/src/IdentityServer/Hosting/IEndpointResultGenerator.cs +++ b/src/IdentityServer/Hosting/IHttpResponseWriter.cs @@ -8,14 +8,15 @@ namespace Duende.IdentityServer.Hosting; /// -/// Endpoint result generator +/// Contract for a service that writes appropriate http responses for objects. /// -public interface IEndpointResultGenerator +public interface IHttpResponseWriter where T : IEndpointResult { /// /// Writes the endpoint result to the HTTP response. /// - Task ExecuteAsync(T result, HttpContext context); + Task WriteHttpResponse(T result, HttpContext context); } diff --git a/src/IdentityServer/Services/IPushedAuthorizationSerializer.cs b/src/IdentityServer/Services/IPushedAuthorizationSerializer.cs index 4978ef661..5ccff2a98 100644 --- a/src/IdentityServer/Services/IPushedAuthorizationSerializer.cs +++ b/src/IdentityServer/Services/IPushedAuthorizationSerializer.cs @@ -7,7 +7,8 @@ namespace Duende.IdentityServer.Services; /// -/// A service that can serialize and deserialize pushed authorization requests. +/// Contract for a service that can serialize and deserialize pushed +/// authorization requests. /// public interface IPushedAuthorizationSerializer { diff --git a/src/IdentityServer/Services/IPushedAuthorizationService.cs b/src/IdentityServer/Services/IPushedAuthorizationService.cs index d414ea8b8..3421fa842 100644 --- a/src/IdentityServer/Services/IPushedAuthorizationService.cs +++ b/src/IdentityServer/Services/IPushedAuthorizationService.cs @@ -9,7 +9,8 @@ namespace Duende.IdentityServer.Services; /// -/// Contract for a service that performs logical operations on pushed authorization requests. +/// Contract for a service that performs high-level operations on pushed +/// authorization requests. /// public interface IPushedAuthorizationService { diff --git a/test/IdentityServer.UnitTests/Endpoints/EndSession/EndSessionCallbackResultTests.cs b/test/IdentityServer.UnitTests/Endpoints/EndSession/EndSessionCallbackResultTests.cs index 44f91da22..88a00f99d 100644 --- a/test/IdentityServer.UnitTests/Endpoints/EndSession/EndSessionCallbackResultTests.cs +++ b/test/IdentityServer.UnitTests/Endpoints/EndSession/EndSessionCallbackResultTests.cs @@ -19,7 +19,7 @@ public class EndSessionCallbackResultTests private readonly EndSessionCallbackValidationResult _validationResult; private readonly IdentityServerOptions _options; - private readonly EndSessionCallbackResultGenerator _subject; + private readonly EndSessionCallbackHttpWriter _subject; public EndSessionCallbackResultTests() { @@ -28,7 +28,7 @@ public EndSessionCallbackResultTests() IsError = false, }; _options = new IdentityServerOptions(); - _subject = new EndSessionCallbackResultGenerator(_options); + _subject = new EndSessionCallbackHttpWriter(_options); } [Fact] @@ -39,7 +39,7 @@ public async Task default_options_should_emit_frame_src_csp_headers() var ctx = new DefaultHttpContext(); ctx.Request.Method = "GET"; - await _subject.ExecuteAsync(new EndSessionCallbackResult(_validationResult), ctx); + await _subject.WriteHttpResponse(new EndSessionCallbackResult(_validationResult), ctx); ctx.Response.Headers["Content-Security-Policy"].First().Should().Contain("frame-src http://foo"); } @@ -53,7 +53,7 @@ public async Task relax_csp_options_should_prevent_frame_src_csp_headers() var ctx = new DefaultHttpContext(); ctx.Request.Method = "GET"; - await _subject.ExecuteAsync(new EndSessionCallbackResult(_validationResult), ctx); + await _subject.WriteHttpResponse(new EndSessionCallbackResult(_validationResult), ctx); ctx.Response.Headers["Content-Security-Policy"].FirstOrDefault().Should().BeNull(); } diff --git a/test/IdentityServer.UnitTests/Endpoints/Results/AuthorizeResultTests.cs b/test/IdentityServer.UnitTests/Endpoints/Results/AuthorizeResultTests.cs index d7a861516..a46789289 100644 --- a/test/IdentityServer.UnitTests/Endpoints/Results/AuthorizeResultTests.cs +++ b/test/IdentityServer.UnitTests/Endpoints/Results/AuthorizeResultTests.cs @@ -26,7 +26,7 @@ namespace UnitTests.Endpoints.Results; public class AuthorizeResultTests { - private AuthorizeResultGenerator _subject; + private AuthorizeHttpWriter _subject; private AuthorizeResponse _response = new AuthorizeResponse(); private IdentityServerOptions _options = new IdentityServerOptions(); @@ -47,7 +47,7 @@ public AuthorizeResultTests() _options.UserInteraction.ErrorUrl = "~/error"; _options.UserInteraction.ErrorIdParameter = "errorId"; - _subject = new AuthorizeResultGenerator(_options, _mockUserSession, new TestPushedAuthorizationService(), _mockErrorMessageStore, _urls, new StubClock()); + _subject = new AuthorizeHttpWriter(_options, _mockUserSession, new TestPushedAuthorizationService(), _mockErrorMessageStore, _urls, new StubClock()); } [Fact] @@ -55,7 +55,7 @@ public async Task error_should_redirect_to_error_page_and_passs_info() { _response.Error = "some_error"; - await _subject.ExecuteAsync(new AuthorizeResult(_response), _context); + await _subject.WriteHttpResponse(new AuthorizeResult(_response), _context); _mockErrorMessageStore.Messages.Count.Should().Be(1); _context.Response.StatusCode.Should().Be(302); @@ -80,7 +80,7 @@ public async Task prompt_none_errors_should_return_to_client(string error) PromptModes = new[] { "none" } }; - await _subject.ExecuteAsync(new AuthorizeResult(_response), _context); + await _subject.WriteHttpResponse(new AuthorizeResult(_response), _context); _mockUserSession.Clients.Count.Should().Be(0); _context.Response.StatusCode.Should().Be(302); @@ -104,7 +104,7 @@ public async Task prompt_none_errors_for_anonymous_users_should_include_session_ }; _response.SessionState = "some_session_state"; - await _subject.ExecuteAsync(new AuthorizeResult(_response), _context); + await _subject.WriteHttpResponse(new AuthorizeResult(_response), _context); _mockUserSession.Clients.Count.Should().Be(0); _context.Response.StatusCode.Should().Be(302); @@ -125,7 +125,7 @@ public async Task access_denied_should_return_to_client() RedirectUri = "http://client/callback" }; - await _subject.ExecuteAsync(new AuthorizeResult(_response), _context); + await _subject.WriteHttpResponse(new AuthorizeResult(_response), _context); _mockUserSession.Clients.Count.Should().Be(0); _context.Response.StatusCode.Should().Be(302); @@ -149,7 +149,7 @@ public async Task success_should_add_client_to_client_list() RedirectUri = "http://client/callback" }; - await _subject.ExecuteAsync(new AuthorizeResult(_response), _context); + await _subject.WriteHttpResponse(new AuthorizeResult(_response), _context); _mockUserSession.Clients.Should().Contain("client"); } @@ -165,7 +165,7 @@ public async Task query_mode_should_pass_results_in_query() State = "state" }; - await _subject.ExecuteAsync(new AuthorizeResult(_response), _context); + await _subject.WriteHttpResponse(new AuthorizeResult(_response), _context); _context.Response.StatusCode.Should().Be(302); _context.Response.Headers["Cache-Control"].First().Should().Contain("no-store"); @@ -187,7 +187,7 @@ public async Task fragment_mode_should_pass_results_in_fragment() State = "state" }; - await _subject.ExecuteAsync(new AuthorizeResult(_response), _context); + await _subject.WriteHttpResponse(new AuthorizeResult(_response), _context); _context.Response.StatusCode.Should().Be(302); _context.Response.Headers["Cache-Control"].First().Should().Contain("no-store"); @@ -209,7 +209,7 @@ public async Task form_post_mode_should_pass_results_in_body() State = "state" }; - await _subject.ExecuteAsync(new AuthorizeResult(_response), _context); + await _subject.WriteHttpResponse(new AuthorizeResult(_response), _context); _context.Response.StatusCode.Should().Be(200); _context.Response.ContentType.Should().StartWith("text/html"); @@ -243,7 +243,7 @@ public async Task form_post_mode_should_add_unsafe_inline_for_csp_level_1() _options.Csp.Level = CspLevel.One; - await _subject.ExecuteAsync(new AuthorizeResult(_response), _context); + await _subject.WriteHttpResponse(new AuthorizeResult(_response), _context); _context.Response.Headers["Content-Security-Policy"].First().Should().Contain($"script-src 'unsafe-inline' '{IdentityServerConstants.ContentSecurityPolicyHashes.AuthorizeScript}'"); _context.Response.Headers["X-Content-Security-Policy"].First().Should().Contain($"script-src 'unsafe-inline' '{IdentityServerConstants.ContentSecurityPolicyHashes.AuthorizeScript}'"); @@ -262,7 +262,7 @@ public async Task form_post_mode_should_not_add_deprecated_header_when_it_is_dis _options.Csp.AddDeprecatedHeader = false; - await _subject.ExecuteAsync(new AuthorizeResult(_response), _context); + await _subject.WriteHttpResponse(new AuthorizeResult(_response), _context); _context.Response.Headers["Content-Security-Policy"].First().Should().Contain($"script-src '{IdentityServerConstants.ContentSecurityPolicyHashes.AuthorizeScript}'"); _context.Response.Headers["X-Content-Security-Policy"].Should().BeEmpty(); diff --git a/test/IdentityServer.UnitTests/Endpoints/Results/CheckSessionResultTests.cs b/test/IdentityServer.UnitTests/Endpoints/Results/CheckSessionResultTests.cs index 36d22a0b2..b95149cd5 100644 --- a/test/IdentityServer.UnitTests/Endpoints/Results/CheckSessionResultTests.cs +++ b/test/IdentityServer.UnitTests/Endpoints/Results/CheckSessionResultTests.cs @@ -17,7 +17,7 @@ namespace UnitTests.Endpoints.Results; public class CheckSessionResultTests { - private CheckSessionResultGenerator _subject; + private CheckSessionHttpWriter _subject; private IdentityServerOptions _options = new IdentityServerOptions(); @@ -31,13 +31,13 @@ public CheckSessionResultTests() _options.Authentication.CheckSessionCookieName = "foobar"; - _subject = new CheckSessionResultGenerator(_options); + _subject = new CheckSessionHttpWriter(_options); } [Fact] public async Task should_pass_results_in_body() { - await _subject.ExecuteAsync(new CheckSessionResult(), _context); + await _subject.WriteHttpResponse(new CheckSessionResult(), _context); _context.Response.StatusCode.Should().Be(200); _context.Response.ContentType.Should().StartWith("text/html"); @@ -58,7 +58,7 @@ public async Task form_post_mode_should_add_unsafe_inline_for_csp_level_1() { _options.Csp.Level = CspLevel.One; - await _subject.ExecuteAsync(new CheckSessionResult(), _context); + await _subject.WriteHttpResponse(new CheckSessionResult(), _context); _context.Response.Headers["Content-Security-Policy"].First().Should().Contain($"script-src 'unsafe-inline' '{IdentityServerConstants.ContentSecurityPolicyHashes.CheckSessionScript}'"); _context.Response.Headers["X-Content-Security-Policy"].First().Should().Contain($"script-src 'unsafe-inline' '{IdentityServerConstants.ContentSecurityPolicyHashes.CheckSessionScript}'"); @@ -69,7 +69,7 @@ public async Task form_post_mode_should_not_add_deprecated_header_when_it_is_dis { _options.Csp.AddDeprecatedHeader = false; - await _subject.ExecuteAsync(new CheckSessionResult(), _context); + await _subject.WriteHttpResponse(new CheckSessionResult(), _context); _context.Response.Headers["Content-Security-Policy"].First().Should().Contain($"script-src '{IdentityServerConstants.ContentSecurityPolicyHashes.CheckSessionScript}'"); _context.Response.Headers["X-Content-Security-Policy"].Should().BeEmpty(); @@ -82,7 +82,7 @@ public async Task form_post_mode_should_not_add_deprecated_header_when_it_is_dis public async Task can_change_cached_cookiename(string cookieName) { _options.Authentication.CheckSessionCookieName = cookieName; - await _subject.ExecuteAsync(new CheckSessionResult(), _context); + await _subject.WriteHttpResponse(new CheckSessionResult(), _context); _context.Response.Body.Seek(0, SeekOrigin.Begin); using (var rdr = new StreamReader(_context.Response.Body)) { diff --git a/test/IdentityServer.UnitTests/Endpoints/Results/EndSessionCallbackResultTests.cs b/test/IdentityServer.UnitTests/Endpoints/Results/EndSessionCallbackResultTests.cs index 5d9d22508..6a4699ed4 100644 --- a/test/IdentityServer.UnitTests/Endpoints/Results/EndSessionCallbackResultTests.cs +++ b/test/IdentityServer.UnitTests/Endpoints/Results/EndSessionCallbackResultTests.cs @@ -18,7 +18,7 @@ namespace UnitTests.Endpoints.Results; public class EndSessionCallbackResultTests { - private EndSessionCallbackResultGenerator _subject; + private EndSessionCallbackHttpWriter _subject; private EndSessionCallbackValidationResult _result = new EndSessionCallbackValidationResult(); private IdentityServerOptions _options = TestIdentityServerOptions.Create(); @@ -31,7 +31,7 @@ public EndSessionCallbackResultTests() _context.Request.Host = new HostString("server"); _context.Response.Body = new MemoryStream(); - _subject = new EndSessionCallbackResultGenerator(_options); + _subject = new EndSessionCallbackHttpWriter(_options); } [Fact] @@ -39,7 +39,7 @@ public async Task error_should_return_400() { _result.IsError = true; - await _subject.ExecuteAsync(new EndSessionCallbackResult(_result), _context); + await _subject.WriteHttpResponse(new EndSessionCallbackResult(_result), _context); _context.Response.StatusCode.Should().Be(400); } @@ -50,7 +50,7 @@ public async Task success_should_render_html_and_iframes() _result.IsError = false; _result.FrontChannelLogoutUrls = new string[] { "http://foo.com", "http://bar.com" }; - await _subject.ExecuteAsync(new EndSessionCallbackResult(_result), _context); + await _subject.WriteHttpResponse(new EndSessionCallbackResult(_result), _context); _context.Response.ContentType.Should().StartWith("text/html"); _context.Response.Headers["Cache-Control"].First().Should().Contain("no-store"); @@ -78,7 +78,7 @@ public async Task fsuccess_should_add_unsafe_inline_for_csp_level_1() _options.Csp.Level = CspLevel.One; - await _subject.ExecuteAsync(new EndSessionCallbackResult(_result), _context); + await _subject.WriteHttpResponse(new EndSessionCallbackResult(_result), _context); _context.Response.Headers["Content-Security-Policy"].First().Should().Contain("style-src 'unsafe-inline' 'sha256-e6FQZewefmod2S/5T11pTXjzE2vn3/8GRwWOs917YE4='"); _context.Response.Headers["X-Content-Security-Policy"].First().Should().Contain("style-src 'unsafe-inline' 'sha256-e6FQZewefmod2S/5T11pTXjzE2vn3/8GRwWOs917YE4='"); @@ -91,7 +91,7 @@ public async Task form_post_mode_should_not_add_deprecated_header_when_it_is_dis _options.Csp.AddDeprecatedHeader = false; - await _subject.ExecuteAsync(new EndSessionCallbackResult(_result), _context); + await _subject.WriteHttpResponse(new EndSessionCallbackResult(_result), _context); _context.Response.Headers["Content-Security-Policy"].First().Should().Contain("style-src 'sha256-e6FQZewefmod2S/5T11pTXjzE2vn3/8GRwWOs917YE4='"); _context.Response.Headers["X-Content-Security-Policy"].Should().BeEmpty(); diff --git a/test/IdentityServer.UnitTests/Endpoints/Results/EndSessionResultTests.cs b/test/IdentityServer.UnitTests/Endpoints/Results/EndSessionResultTests.cs index 9d1cef490..bded4e96c 100644 --- a/test/IdentityServer.UnitTests/Endpoints/Results/EndSessionResultTests.cs +++ b/test/IdentityServer.UnitTests/Endpoints/Results/EndSessionResultTests.cs @@ -20,7 +20,7 @@ namespace UnitTests.Endpoints.Results; public class EndSessionResultTests { - private EndSessionResultGenerator _subject; + private EndSessionHttpWriter _subject; private EndSessionValidationResult _result = new EndSessionValidationResult(); private IdentityServerOptions _options = new IdentityServerOptions(); @@ -39,7 +39,7 @@ public EndSessionResultTests() _options.UserInteraction.LogoutUrl = "~/logout"; _options.UserInteraction.LogoutIdParameter = "logoutId"; - _subject = new EndSessionResultGenerator(_options, new StubClock(), _urls, _mockLogoutMessageStore); + _subject = new EndSessionHttpWriter(_options, new StubClock(), _urls, _mockLogoutMessageStore); } [Fact] @@ -55,7 +55,7 @@ public async Task validated_signout_should_pass_logout_message() PostLogOutUri = "http://client/post-logout-callback" }; - await _subject.ExecuteAsync(new EndSessionResult(_result), _context); + await _subject.WriteHttpResponse(new EndSessionResult(_result), _context); _mockLogoutMessageStore.Messages.Count.Should().Be(1); var location = _context.Response.Headers["Location"].Single(); @@ -70,7 +70,7 @@ public async Task unvalidated_signout_should_not_pass_logout_message() { _result.IsError = false; - await _subject.ExecuteAsync(new EndSessionResult(_result), _context); + await _subject.WriteHttpResponse(new EndSessionResult(_result), _context); _mockLogoutMessageStore.Messages.Count.Should().Be(0); var location = _context.Response.Headers["Location"].Single(); @@ -93,7 +93,7 @@ public async Task error_result_should_not_pass_logout_message() PostLogOutUri = "http://client/post-logout-callback" }; - await _subject.ExecuteAsync(new EndSessionResult(_result), _context); + await _subject.WriteHttpResponse(new EndSessionResult(_result), _context); _mockLogoutMessageStore.Messages.Count.Should().Be(0); var location = _context.Response.Headers["Location"].Single();