brockallen / BrockAllen.MembershipReboot

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

Saving metadata ("Properties" dictionary) with a Claim #675

Closed philpowers closed 7 years ago

philpowers commented 7 years ago

I ran into an issue with ASP.NET Identity where I wanted to be able to persist metadata associated with a specific Claim into the DB. At first, this looked trivial and I simply added the metadata as an entry in the Claim object's "Properties" dictionary:

https://msdn.microsoft.com/en-us/library/system.security.claims.claim.properties(v=vs.110).aspx

Unfortunately, it looks like ASP.NET Identity essentially ignores these properties and therefore the metadata is lost whenever the claims are read from the DB. Additionally, it looks like the EF backing store for ASP.NET Identity doesn't give an easy way to create the "TUserClaim" object before it populates the DB - meaning that even if I extend the default TUserClaim, there's still no easy way to persist the extra fields.

Anyway, is this a scenario that's supported by MembershipReboot? I scanned through the code, and it looks like it is also only persisting the "Type" and "Value" fields of the Claim objects.

brockallen commented 7 years ago

I scanned through the code, and it looks like it is also only persisting the "Type" and "Value" fields of the Claim objects.

You are correct.

philpowers commented 7 years ago

Ok thanks. Is there any means for extending that? Or any other clever ideas for storing Claim-specific metadata? My current solution was to encode the information in the "Value" field and then do pre/post-processing on it wherever it's coming out of the DB.

brockallen commented 7 years ago

I doubt it'd be easy to extend. Perhaps overloading the value would work... you could do a decorator pattern on the repository...

philpowers commented 7 years ago

Sounds good. Thanks for the info.