From d30256dd5fd34044c92798a16f7bae01703bfc01 Mon Sep 17 00:00:00 2001 From: OpenIddict Bot <32257313+openiddict-bot@users.noreply.github.com> Date: Tue, 11 Oct 2022 17:04:06 +0000 Subject: [PATCH] Update the sponsors section --- .../Primitives/OpenIddictExtensions.cs | 2 +- .../OpenIddictClientSystemNetHttpHandlers.cs | 9 +++++++++ .../OpenIddictValidationSystemNetHttpHandlers.cs | 9 +++++++++ .../Primitives/OpenIddictExtensionsTests.cs | 5 +---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs index d5ebd167..73ac83d2 100644 --- a/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs +++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs @@ -1277,7 +1277,7 @@ public static class OpenIddictExtensions foreach (var element in value.EnumerateArray()) { - var item = element.ToString(); + var item = element.GetString()!; if (set.Add(item)) { identity.AddClaim(new Claim( diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs index 9c7e7996..d3f10dfd 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs @@ -347,6 +347,10 @@ public static partial class OpenIddictClientSystemNetHttpHandlers try { + // Note: HttpCompletionOption.ResponseContentRead is deliberately used to force the + // response stream to be buffered so that can it can be read multiple times if needed + // (e.g if the JSON deserialization process fails, the stream is read as a string + // during a second pass a second time for logging/debuggability purposes). response = await client.SendAsync(request, HttpCompletionOption.ResponseContentRead); } @@ -524,7 +528,12 @@ public static partial class OpenIddictClientSystemNetHttpHandlers // to the HTTP response message to use the specified stream transformations. if (stream is not null) { + // Note: StreamContent.LoadIntoBufferAsync is deliberately used to force the stream + // content to be buffered so that can it can be read multiple times if needed + // (e.g if the JSON deserialization process fails, the stream is read as a string + // during a second pass a second time for logging/debuggability purposes). var content = new StreamContent(stream); + await content.LoadIntoBufferAsync(); // Copy the headers from the original content to the new instance. foreach (var header in response.Content.Headers) diff --git a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs index 748c9193..ab38845e 100644 --- a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs +++ b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs @@ -348,6 +348,10 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers try { + // Note: HttpCompletionOption.ResponseContentRead is deliberately used to force the + // response stream to be buffered so that can it can be read multiple times if needed + // (e.g if the JSON deserialization process fails, the stream is read as a string + // during a second pass a second time for logging/debuggability purposes). response = await client.SendAsync(request, HttpCompletionOption.ResponseContentRead); } @@ -525,7 +529,12 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers // to the HTTP response message to use the specified stream transformations. if (stream is not null) { + // Note: StreamContent.LoadIntoBufferAsync is deliberately used to force the stream + // content to be buffered so that can it can be read multiple times if needed + // (e.g if the JSON deserialization process fails, the stream is read as a string + // during a second pass a second time for logging/debuggability purposes). var content = new StreamContent(stream); + await content.LoadIntoBufferAsync(); // Copy the headers from the original content to the new instance. foreach (var header in response.Content.Headers) diff --git a/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictExtensionsTests.cs b/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictExtensionsTests.cs index 71c50164..11b8a721 100644 --- a/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictExtensionsTests.cs +++ b/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictExtensionsTests.cs @@ -2127,7 +2127,7 @@ public class OpenIddictExtensionsTests var identity = new ClaimsIdentity(); // Act - identity.AddClaims("type", JsonSerializer.Deserialize(@"[""Fabrikam"",""Contoso"",42]"), "issuer"); + identity.AddClaims("type", JsonSerializer.Deserialize(@"[""Fabrikam"",""Contoso""]"), "issuer"); // Assert var claims = identity.FindAll("type").ToArray(); @@ -2137,9 +2137,6 @@ public class OpenIddictExtensionsTests Assert.Equal("Contoso", claims[1].Value); Assert.Equal(ClaimValueTypes.String, claims[1].ValueType); Assert.Equal("issuer", claims[1].Issuer); - Assert.Equal("42", claims[2].Value); - Assert.Equal(ClaimValueTypes.Integer32, claims[2].ValueType); - Assert.Equal("issuer", claims[2].Issuer); } [Fact]