diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Device.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Device.cs index 5ca3cedb..90d262f4 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Device.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Device.cs @@ -91,9 +91,10 @@ namespace OpenIddict.Server.AspNetCore throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); } - // Note: this handler only redirects the user agent to the address specified - // in the AuthenticationProperties if the error is an access_denied error. - if (!string.Equals(context.Response.Error, Errors.AccessDenied, StringComparison.Ordinal)) + // Note: this handler only redirects the user agent to the address specified in + // the properties when there's no error or if the error is an access_denied error. + if (!string.IsNullOrEmpty(context.Response.Error) && + !string.Equals(context.Response.Error, Errors.AccessDenied, StringComparison.Ordinal)) { return default; } diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs index d97b7a2e..98d78bfd 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs @@ -53,11 +53,11 @@ namespace OpenIddict.Server.AspNetCore RemoveCachedRequest.Descriptor, AttachHttpResponseCode.Descriptor, AttachCacheControlHeader.Descriptor, + ProcessHostRedirectionResponse.Descriptor, ProcessPassthroughErrorResponse.Descriptor, ProcessStatusCodePagesErrorResponse.Descriptor, ProcessLocalErrorResponse.Descriptor, ProcessQueryResponse.Descriptor, - ProcessHostRedirectionResponse.Descriptor, ProcessEmptyResponse.Descriptor); /// @@ -389,7 +389,7 @@ namespace OpenIddict.Server.AspNetCore = OpenIddictServerHandlerDescriptor.CreateBuilder() .AddFilter() .UseSingletonHandler() - .SetOrder(ProcessQueryResponse.Descriptor.Order + 250) + .SetOrder(ProcessPassthroughErrorResponse.Descriptor.Order + 250) .SetType(OpenIddictServerHandlerType.BuiltIn) .Build(); @@ -409,6 +409,14 @@ namespace OpenIddict.Server.AspNetCore throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); } + // Note: this handler only executes if no post_logout_redirect_uri was specified + // and if the response doesn't correspond to an error, that must be handled locally. + if (!string.IsNullOrEmpty(context.PostLogoutRedirectUri) || + !string.IsNullOrEmpty(context.Response.Error)) + { + return default; + } + var properties = context.Transaction.GetProperty(typeof(AuthenticationProperties).FullName!); if (properties is not null && !string.IsNullOrEmpty(properties.RedirectUri)) { diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Device.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Device.cs index 04e634b5..41825267 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Device.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Device.cs @@ -90,9 +90,10 @@ namespace OpenIddict.Server.Owin throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); } - // Note: this handler only redirects the user agent to the address specified - // in the AuthenticationProperties if the error is an access_denied error. - if (!string.Equals(context.Response.Error, Errors.AccessDenied, StringComparison.Ordinal)) + // Note: this handler only redirects the user agent to the address specified in + // the properties when there's no error or if the error is an access_denied error. + if (!string.IsNullOrEmpty(context.Response.Error) && + !string.Equals(context.Response.Error, Errors.AccessDenied, StringComparison.Ordinal)) { return default; } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs index 213c74ed..ce199ebe 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs @@ -53,10 +53,10 @@ namespace OpenIddict.Server.Owin RemoveCachedRequest.Descriptor, AttachHttpResponseCode.Descriptor, AttachCacheControlHeader.Descriptor, + ProcessHostRedirectionResponse.Descriptor, ProcessPassthroughErrorResponse.Descriptor, ProcessLocalErrorResponse.Descriptor, ProcessQueryResponse.Descriptor, - ProcessHostRedirectionResponse.Descriptor, ProcessEmptyResponse.Descriptor); /// @@ -371,24 +371,24 @@ namespace OpenIddict.Server.Owin } /// - /// Contains the logic responsible of processing verification responses that should trigger a host redirection. + /// Contains the logic responsible of processing logout responses that should trigger a host redirection. /// Note: this handler is not used when the OpenID Connect request is not initially handled by OWIN. /// - public class ProcessHostRedirectionResponse : IOpenIddictServerHandler + public class ProcessHostRedirectionResponse : IOpenIddictServerHandler { /// /// Gets the default descriptor definition assigned to this handler. /// public static OpenIddictServerHandlerDescriptor Descriptor { get; } - = OpenIddictServerHandlerDescriptor.CreateBuilder() + = OpenIddictServerHandlerDescriptor.CreateBuilder() .AddFilter() .UseSingletonHandler() - .SetOrder(ProcessQueryResponse.Descriptor.Order + 250) + .SetOrder(ProcessPassthroughErrorResponse.Descriptor.Order + 250) .SetType(OpenIddictServerHandlerType.BuiltIn) .Build(); /// - public ValueTask HandleAsync(ApplyVerificationResponseContext context) + public ValueTask HandleAsync(ApplyLogoutResponseContext context) { if (context is null) { @@ -403,9 +403,10 @@ namespace OpenIddict.Server.Owin throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); } - // Note: this handler only redirects the user agent to the address specified - // in the AuthenticationProperties if the error is an access_denied error. - if (!string.Equals(context.Response.Error, Errors.AccessDenied, StringComparison.Ordinal)) + // Note: this handler only executes if no post_logout_redirect_uri was specified + // and if the response doesn't correspond to an error, that must be handled locally. + if (!string.IsNullOrEmpty(context.PostLogoutRedirectUri) || + !string.IsNullOrEmpty(context.Response.Error)) { return default; }