brockallen / BrockAllen.MembershipReboot

MembershipReboot is a user identity management and authentication library.
Other
743 stars 239 forks source link

Claims are duplicating when saving #669

Closed stevengopmo closed 7 years ago

stevengopmo commented 8 years ago

I'm having a really strange situation using Membership Reboot as my backend for IdentityServer3. I'm using RavenDB as my db. Whenever I login the Hierarchical user gets saved and the number of claims I have doubled. It basically duplicates all the existing claims.

Any ideas where I might be able to start with this? Looking at the code in IdentityServer3.MembershipReboot.MembershipRebootUserService it doesn't seem as if there's any obvious place that would be updating the user, I think it's all coming from the BrockAllen.MembershipReboot.UserAccountService<TAccount>

brockallen commented 8 years ago

Not sure... You might have to debug into it all to uncover the issue.

stevengopmo commented 8 years ago

I haven't figured out direct cause yet, but adding JsonIgnore to the Claims public property seemed to solve. Somehow it seems like both the Claims property and the ClaimsCollection are being enumerated to get the claims which is causing duplication. If it helps anyone, my CustomUser Claims property now looks like

        [JsonIgnore]
        public override IEnumerable<UserClaim> Claims => base.Claims;
brockallen commented 8 years ago

Ah sounds like you're deriving from the entity base and adding your own properties. I guess the raven code thinks it should store those as well.

stevengopmo commented 8 years ago

yes I am, I switched to HierarchicalUser to see if it was my class but still the same. Previous version I use of MembershipReboot does not do this. Raven does store both properties in the db as separate collections, but when reading I've never had the duplication problem. Of course I'm also using a newer version of Raven in this project so I'm not sure whether it's Raven or something funky in my custom classes for interacting with Raven & Membership & IdSrv. If I do find the root cause I'll document here, but at least I have a simple workaround.

stevengopmo commented 8 years ago

adding the JsonIgnore also solved the problem of both the property and the field being stored in the db.