Browse Source

Add an option allowing to suppress JSON response indentation in the ASP.NET Core and OWIN server hosts

pull/1882/head
Kévin Chalet 3 years ago
parent
commit
e8c0e4b05c
  1. 7
      src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreBuilder.cs
  2. 7
      src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs
  3. 5
      src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreOptions.cs
  4. 7
      src/OpenIddict.Server.Owin/OpenIddictServerOwinBuilder.cs
  5. 7
      src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs
  6. 5
      src/OpenIddict.Server.Owin/OpenIddictServerOwinOptions.cs

7
src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreBuilder.cs

@ -146,6 +146,13 @@ public sealed class OpenIddictServerAspNetCoreBuilder
public OpenIddictServerAspNetCoreBuilder EnableStatusCodePagesIntegration()
=> Configure(options => options.EnableStatusCodePagesIntegration = true);
/// <summary>
/// Suppresses indentation for the JSON responses returned by the ASP.NET Core host.
/// </summary>
/// <returns>The <see cref="OpenIddictServerAspNetCoreBuilder"/> instance.</returns>
public OpenIddictServerAspNetCoreBuilder SuppressJsonResponseIndentation()
=> Configure(options => options.SuppressJsonResponseIndentation = true);
/// <summary>
/// Sets the realm returned to the caller as part of the WWW-Authenticate header.
/// </summary>

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

@ -1093,6 +1093,11 @@ public static partial class OpenIddictServerAspNetCoreHandlers
/// </summary>
public sealed class ProcessJsonResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{
private readonly IOptionsMonitor<OpenIddictServerAspNetCoreOptions> _options;
public ProcessJsonResponse(IOptionsMonitor<OpenIddictServerAspNetCoreOptions> options)
=> _options = options ?? throw new ArgumentNullException(nameof(options));
/// <summary>
/// Gets the default descriptor definition assigned to this handler.
/// </summary>
@ -1125,7 +1130,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers
using var writer = new Utf8JsonWriter(stream, new JsonWriterOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
Indented = true
Indented = !_options.CurrentValue.SuppressJsonResponseIndentation
});
context.Transaction.Response.WriteTo(writer);

5
src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreOptions.cs

@ -93,6 +93,11 @@ public sealed class OpenIddictServerAspNetCoreOptions : AuthenticationSchemeOpti
/// </summary>
public bool EnableStatusCodePagesIntegration { get; set; }
/// <summary>
/// Gets or sets a boolean whether JSON response indentation should be suppressed or not.
/// </summary>
public bool SuppressJsonResponseIndentation { get; set; }
/// <summary>
/// Gets or sets the optional "realm" value returned to the caller as part of the WWW-Authenticate header.
/// </summary>

7
src/OpenIddict.Server.Owin/OpenIddictServerOwinBuilder.cs

@ -135,6 +135,13 @@ public sealed class OpenIddictServerOwinBuilder
public OpenIddictServerOwinBuilder EnableLogoutRequestCaching()
=> Configure(options => options.EnableLogoutRequestCaching = true);
/// <summary>
/// Suppresses indentation for the JSON responses returned by the OWIN host.
/// </summary>
/// <returns>The <see cref="OpenIddictServerOwinBuilder"/> instance.</returns>
public OpenIddictServerOwinBuilder SuppressJsonResponseIndentation()
=> Configure(options => options.SuppressJsonResponseIndentation = true);
/// <summary>
/// Sets the realm returned to the caller as part of the WWW-Authenticate header.
/// </summary>

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

@ -1265,6 +1265,11 @@ public static partial class OpenIddictServerOwinHandlers
/// </summary>
public sealed class ProcessJsonResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{
private readonly IOptionsMonitor<OpenIddictServerOwinOptions> _options;
public ProcessJsonResponse(IOptionsMonitor<OpenIddictServerOwinOptions> options)
=> _options = options ?? throw new ArgumentNullException(nameof(options));
/// <summary>
/// Gets the default descriptor definition assigned to this handler.
/// </summary>
@ -1297,7 +1302,7 @@ public static partial class OpenIddictServerOwinHandlers
using var writer = new Utf8JsonWriter(stream, new JsonWriterOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
Indented = true
Indented = !_options.CurrentValue.SuppressJsonResponseIndentation
});
context.Transaction.Response.WriteTo(writer);

5
src/OpenIddict.Server.Owin/OpenIddictServerOwinOptions.cs

@ -90,6 +90,11 @@ public sealed class OpenIddictServerOwinOptions : AuthenticationOptions
/// </summary>
public bool EnableLogoutRequestCaching { get; set; }
/// <summary>
/// Gets or sets a boolean whether JSON response indentation should be suppressed or not.
/// </summary>
public bool SuppressJsonResponseIndentation { get; set; }
/// <summary>
/// Gets or sets the optional "realm" value returned to the caller as part of the WWW-Authenticate header.
/// </summary>

Loading…
Cancel
Save