System.Security.Claims.Claim de-serialization issues

I am implementing an oAuth server and you need to keep the update tokens, for this I (at the moment) have chosen to serialize tokens in JSON.

So far I see that JSON includes everything that is needed for rehydration when I de-serialize with token.FromJson () inline statements are not restored correctly.

So far, I have considered JsonConverter inheritance to create a claims converter, but I don’t see a way to configure the global JsConfig to use it :(

Can someone point me in a good direction?

+5
source share
1 answer

So...

Avoiding code and returning did the trick!

Instead of using JsonConverter, you need to use the generic version of JsConfig when changing / overriding ServiceStack behavior in a specific class, just attach the following to your services start code, for example.

JsConfig<Claim>.SerializeFn = claim => string.Format("{0}|{1}", claim.Type, claim.Value); JsConfig<Claim>.DeSerializeFn = claimDetails => { var values = claimDetails.Split('|'); return new Claim(values[0], values[1]); }; 
+3
source

All Articles