Skip to content

Commit 18d2168

Browse files
Do not serialize Parameters
Explicitly prevent the Parameters dictionary from being included in the deserialized payload. See dotnet#31330 (comment).
1 parent 8508279 commit 18d2168

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Http/Authentication.Abstractions/src/AuthenticationProperties.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public AuthenticationProperties Clone()
6565
/// Collection of parameters that are passed to the authentication handler. These are not intended for
6666
/// serialization or persistence, only for flowing data between call sites.
6767
/// </summary>
68+
[JsonIgnore]
6869
public IDictionary<string, object?> Parameters { get; }
6970

7071
/// <summary>

src/Http/Authentication.Core/test/AuthenticationPropertiesTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ public void Roundtrip_Serializes_With_SystemTextJson()
320320
props.Parameters.Add("baz", "quux");
321321

322322
var json = JsonSerializer.Serialize(props);
323+
324+
// Verify that Parameters was not serialized
325+
Assert.NotNull(json);
326+
Assert.DoesNotContain("baz", json);
327+
Assert.DoesNotContain("quux", json);
328+
323329
var deserialized = JsonSerializer.Deserialize<AuthenticationProperties>(json);
324330

325331
Assert.NotNull(deserialized);
@@ -339,6 +345,20 @@ public void Roundtrip_Serializes_With_SystemTextJson()
339345
Assert.Equal(0, deserialized.Parameters.Count);
340346
}
341347

348+
[Fact]
349+
public void Parameters_Is_Not_Deserialized_With_SystemTextJson()
350+
{
351+
var json = @"{""Parameters"":{""baz"":""quux""}}";
352+
353+
var deserialized = JsonSerializer.Deserialize<AuthenticationProperties>(json);
354+
355+
Assert.NotNull(deserialized);
356+
357+
// Ensure that parameters is not deserialized from a raw payload
358+
Assert.NotNull(deserialized!.Parameters);
359+
Assert.Equal(0, deserialized.Parameters.Count);
360+
}
361+
342362
public class MyAuthenticationProperties : AuthenticationProperties
343363
{
344364
public new DateTimeOffset? GetDateTimeOffset(string key)

0 commit comments

Comments
 (0)