Skip to content

JsonSerializer should round trip AuthenticationProperties #20722

Closed

Description

@brockallen

JsonSerializer doesn't seem to seralize/deseralize the AuthenticationProperties class properly.

This test:

[Fact]
public void JsonSerializer_should_round_trip_AuthenticationProperties()
{
    var props = new AuthenticationProperties();
    props.Items.Add("foo", "bar");
            
    var json = JsonSerializer.Serialize(props);
    props = JsonSerializer.Deserialize<AuthenticationProperties>(json);

    props.Items.ContainsKey("foo").Should().BeTrue();
    props.Items["foo"].Should().Be("bar");
}

Fails with:

Message: 
    Expected props.Items.ContainsKey("foo") to be true, but found False.

Using ASP.NET Core 3.1.3.

Please advise.

Activity

  1. added
    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
    on Apr 10, 2020
  2. added
    area-authIncludes: authentication, authorization, OAuth, OIDC, and access token validation
    and removed
    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
    on Apr 10, 2020
  3. pranavkm commented on Apr 10, 2020

    @pranavkm
    Contributor

    The properties do not have public setters. System.Text.Json currently does not have the ability to update a collection property.

  4. brockallen commented on Apr 10, 2020

    @brockallen
    Author

    For what it's worth, prior to ASP.NET Core 3.1, we used JSON.NET and it worked correctly.

  5. analogrelay commented on Apr 16, 2020

    @analogrelay
    Contributor

    The problem here is that Newtonsoft.Json was very aggressive about trying to deserialize the type and would use the dictionary constructor to deserialize it. System.Text.Json does not do that. This is probably best handled by writing a JsonConverter using the new System.Text.Json APIs.

    Can you provide more details as to what your scenario is and why you want to deserialize the Auth Properties?

  6. brockallen commented on Apr 17, 2020

    @brockallen
    Author

    Can you provide more details as to what your scenario is and why you want to deserialize the Auth Properties?

    Because this:

    public ISecureDataFormat<AuthenticationProperties> StateDataFormat { get; set; }

  7. added this to the Backlog milestone on Apr 23, 2020
  8. added
    help wantedUp for grabs. We would accept a PR to help resolve this issue
    on Apr 23, 2020
  9. added a commit that references this issue on Mar 28, 2021
    bf81ce3
  10. modified the milestones: Backlog, 6.0-preview4 on Mar 29, 2021
  11. self-assigned this
    on Mar 29, 2021
  12. added a commit that references this issue on Apr 10, 2021
  13. ghost locked as resolved and limited conversation to collaborators on Apr 30, 2021
  14. added
    enhancementThis issue represents an ask for new feature or an enhancement to an existing one
    on May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-authIncludes: authentication, authorization, OAuth, OIDC, and access token validationenhancementThis issue represents an ask for new feature or an enhancement to an existing onehelp wantedUp for grabs. We would accept a PR to help resolve this issue

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions