|
|
|
@ -820,58 +820,6 @@ namespace OpenIddict.Server.AspNetCore |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Contains the logic responsible of processing empty OpenID Connect responses that should trigger a host redirection.
|
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
|
/// </summary>
|
|
|
|
public class ProcessHostRedirectionResponse<TContext> : IOpenIddictServerHandler<TContext> |
|
|
|
where TContext : BaseRequestContext |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
|
/// </summary>
|
|
|
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|
|
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<TContext>() |
|
|
|
.AddFilter<RequireHttpRequest>() |
|
|
|
.UseSingletonHandler<ProcessHostRedirectionResponse<TContext>>() |
|
|
|
.SetOrder(ProcessJsonResponse<TContext>.Descriptor.Order - 1_000) |
|
|
|
.Build(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Processes the event.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="context">The context associated with the event to process.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
|
|
|
|
/// </returns>
|
|
|
|
public ValueTask HandleAsync([NotNull] TContext context) |
|
|
|
{ |
|
|
|
if (context == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
|
} |
|
|
|
|
|
|
|
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
|
|
|
|
// this may indicate that the request was incorrectly processed by another server stack.
|
|
|
|
var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; |
|
|
|
if (response == null) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("The ASP.NET Core HTTP request cannot be resolved."); |
|
|
|
} |
|
|
|
|
|
|
|
var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName); |
|
|
|
if (properties != null && !string.IsNullOrEmpty(properties.RedirectUri)) |
|
|
|
{ |
|
|
|
response.Redirect(properties.RedirectUri); |
|
|
|
|
|
|
|
context.Logger.LogInformation("The response was successfully returned as a 302 response."); |
|
|
|
context.HandleRequest(); |
|
|
|
} |
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Contains the logic responsible of attaching an appropriate HTTP status code.
|
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
|
@ -1410,6 +1358,58 @@ namespace OpenIddict.Server.AspNetCore |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Contains the logic responsible of processing empty OpenID Connect responses that should trigger a host redirection.
|
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
|
/// </summary>
|
|
|
|
public class ProcessHostRedirectionResponse<TContext> : IOpenIddictServerHandler<TContext> |
|
|
|
where TContext : BaseRequestContext |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
|
/// </summary>
|
|
|
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|
|
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<TContext>() |
|
|
|
.AddFilter<RequireHttpRequest>() |
|
|
|
.UseSingletonHandler<ProcessHostRedirectionResponse<TContext>>() |
|
|
|
.SetOrder(ProcessEmptyResponse<TContext>.Descriptor.Order - 1_000) |
|
|
|
.Build(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Processes the event.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="context">The context associated with the event to process.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
|
|
|
|
/// </returns>
|
|
|
|
public ValueTask HandleAsync([NotNull] TContext context) |
|
|
|
{ |
|
|
|
if (context == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
|
} |
|
|
|
|
|
|
|
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
|
|
|
|
// this may indicate that the request was incorrectly processed by another server stack.
|
|
|
|
var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; |
|
|
|
if (response == null) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("The ASP.NET Core HTTP request cannot be resolved."); |
|
|
|
} |
|
|
|
|
|
|
|
var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName); |
|
|
|
if (properties != null && !string.IsNullOrEmpty(properties.RedirectUri)) |
|
|
|
{ |
|
|
|
response.Redirect(properties.RedirectUri); |
|
|
|
|
|
|
|
context.Logger.LogInformation("The response was successfully returned as a 302 response."); |
|
|
|
context.HandleRequest(); |
|
|
|
} |
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Contains the logic responsible of processing OpenID Connect responses that don't specify any parameter.
|
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
|
|