Browse Source

Update the ProcessHostRedirectionResponse handler to be executed for non-errored verification responses and fix the OWIN version

pull/1098/head
Kévin Chalet 6 years ago
parent
commit
5c7afc13d7
  1. 7
      src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Device.cs
  2. 12
      src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs
  3. 7
      src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Device.cs
  4. 19
      src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs

7
src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Device.cs

@ -91,9 +91,10 @@ namespace OpenIddict.Server.AspNetCore
throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0114));
} }
// Note: this handler only redirects the user agent to the address specified // Note: this handler only redirects the user agent to the address specified in
// in the AuthenticationProperties if the error is an access_denied error. // the properties when there's no error or if the error is an access_denied error.
if (!string.Equals(context.Response.Error, Errors.AccessDenied, StringComparison.Ordinal)) if (!string.IsNullOrEmpty(context.Response.Error) &&
!string.Equals(context.Response.Error, Errors.AccessDenied, StringComparison.Ordinal))
{ {
return default; return default;
} }

12
src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs

@ -53,11 +53,11 @@ namespace OpenIddict.Server.AspNetCore
RemoveCachedRequest.Descriptor, RemoveCachedRequest.Descriptor,
AttachHttpResponseCode<ApplyLogoutResponseContext>.Descriptor, AttachHttpResponseCode<ApplyLogoutResponseContext>.Descriptor,
AttachCacheControlHeader<ApplyLogoutResponseContext>.Descriptor, AttachCacheControlHeader<ApplyLogoutResponseContext>.Descriptor,
ProcessHostRedirectionResponse.Descriptor,
ProcessPassthroughErrorResponse<ApplyLogoutResponseContext, RequireLogoutEndpointPassthroughEnabled>.Descriptor, ProcessPassthroughErrorResponse<ApplyLogoutResponseContext, RequireLogoutEndpointPassthroughEnabled>.Descriptor,
ProcessStatusCodePagesErrorResponse<ApplyLogoutResponseContext>.Descriptor, ProcessStatusCodePagesErrorResponse<ApplyLogoutResponseContext>.Descriptor,
ProcessLocalErrorResponse<ApplyLogoutResponseContext>.Descriptor, ProcessLocalErrorResponse<ApplyLogoutResponseContext>.Descriptor,
ProcessQueryResponse.Descriptor, ProcessQueryResponse.Descriptor,
ProcessHostRedirectionResponse.Descriptor,
ProcessEmptyResponse<ApplyLogoutResponseContext>.Descriptor); ProcessEmptyResponse<ApplyLogoutResponseContext>.Descriptor);
/// <summary> /// <summary>
@ -389,7 +389,7 @@ namespace OpenIddict.Server.AspNetCore
= OpenIddictServerHandlerDescriptor.CreateBuilder<ApplyLogoutResponseContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ApplyLogoutResponseContext>()
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ProcessHostRedirectionResponse>() .UseSingletonHandler<ProcessHostRedirectionResponse>()
.SetOrder(ProcessQueryResponse.Descriptor.Order + 250) .SetOrder(ProcessPassthroughErrorResponse<ApplyLogoutResponseContext, RequireLogoutEndpointPassthroughEnabled>.Descriptor.Order + 250)
.SetType(OpenIddictServerHandlerType.BuiltIn) .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
@ -409,6 +409,14 @@ namespace OpenIddict.Server.AspNetCore
throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); 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<AuthenticationProperties>(typeof(AuthenticationProperties).FullName!); var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName!);
if (properties is not null && !string.IsNullOrEmpty(properties.RedirectUri)) if (properties is not null && !string.IsNullOrEmpty(properties.RedirectUri))
{ {

7
src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Device.cs

@ -90,9 +90,10 @@ namespace OpenIddict.Server.Owin
throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0120));
} }
// Note: this handler only redirects the user agent to the address specified // Note: this handler only redirects the user agent to the address specified in
// in the AuthenticationProperties if the error is an access_denied error. // the properties when there's no error or if the error is an access_denied error.
if (!string.Equals(context.Response.Error, Errors.AccessDenied, StringComparison.Ordinal)) if (!string.IsNullOrEmpty(context.Response.Error) &&
!string.Equals(context.Response.Error, Errors.AccessDenied, StringComparison.Ordinal))
{ {
return default; return default;
} }

19
src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs

@ -53,10 +53,10 @@ namespace OpenIddict.Server.Owin
RemoveCachedRequest.Descriptor, RemoveCachedRequest.Descriptor,
AttachHttpResponseCode<ApplyLogoutResponseContext>.Descriptor, AttachHttpResponseCode<ApplyLogoutResponseContext>.Descriptor,
AttachCacheControlHeader<ApplyLogoutResponseContext>.Descriptor, AttachCacheControlHeader<ApplyLogoutResponseContext>.Descriptor,
ProcessHostRedirectionResponse.Descriptor,
ProcessPassthroughErrorResponse<ApplyLogoutResponseContext, RequireLogoutEndpointPassthroughEnabled>.Descriptor, ProcessPassthroughErrorResponse<ApplyLogoutResponseContext, RequireLogoutEndpointPassthroughEnabled>.Descriptor,
ProcessLocalErrorResponse<ApplyLogoutResponseContext>.Descriptor, ProcessLocalErrorResponse<ApplyLogoutResponseContext>.Descriptor,
ProcessQueryResponse.Descriptor, ProcessQueryResponse.Descriptor,
ProcessHostRedirectionResponse.Descriptor,
ProcessEmptyResponse<ApplyLogoutResponseContext>.Descriptor); ProcessEmptyResponse<ApplyLogoutResponseContext>.Descriptor);
/// <summary> /// <summary>
@ -371,24 +371,24 @@ namespace OpenIddict.Server.Owin
} }
/// <summary> /// <summary>
/// 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. /// Note: this handler is not used when the OpenID Connect request is not initially handled by OWIN.
/// </summary> /// </summary>
public class ProcessHostRedirectionResponse : IOpenIddictServerHandler<ApplyVerificationResponseContext> public class ProcessHostRedirectionResponse : IOpenIddictServerHandler<ApplyLogoutResponseContext>
{ {
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
/// </summary> /// </summary>
public static OpenIddictServerHandlerDescriptor Descriptor { get; } public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<ApplyVerificationResponseContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ApplyLogoutResponseContext>()
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ProcessHostRedirectionResponse>() .UseSingletonHandler<ProcessHostRedirectionResponse>()
.SetOrder(ProcessQueryResponse.Descriptor.Order + 250) .SetOrder(ProcessPassthroughErrorResponse<ApplyLogoutResponseContext, RequireLogoutEndpointPassthroughEnabled>.Descriptor.Order + 250)
.SetType(OpenIddictServerHandlerType.BuiltIn) .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ApplyVerificationResponseContext context) public ValueTask HandleAsync(ApplyLogoutResponseContext context)
{ {
if (context is null) if (context is null)
{ {
@ -403,9 +403,10 @@ namespace OpenIddict.Server.Owin
throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0120));
} }
// Note: this handler only redirects the user agent to the address specified // Note: this handler only executes if no post_logout_redirect_uri was specified
// in the AuthenticationProperties if the error is an access_denied error. // and if the response doesn't correspond to an error, that must be handled locally.
if (!string.Equals(context.Response.Error, Errors.AccessDenied, StringComparison.Ordinal)) if (!string.IsNullOrEmpty(context.PostLogoutRedirectUri) ||
!string.IsNullOrEmpty(context.Response.Error))
{ {
return default; return default;
} }

Loading…
Cancel
Save