Authentication and Authorization Enhancements in .NET 9.0

I’ve reached an interesting point, now that I’ve tried all the approaches I can think of. If you know of any other way to achieve what I’m trying to do, I’d love to hear it.

Goal: To have an Auth0 identity that represents the user and add an additional ClaimsIdentity for each tenant to which the user belongs. Each of those additional identities will have their own claims for that tenant.

I am aware that claims and identities cannot be serialized in their native shape and that I’ll have to map them.

Platform: Blazor with InteractiveAuto rendering.

dotnet 9 approach
I added the AddAuthenticationStateSerialization/AddAuthenticationStateDeserialization methods as per the dotnet 9 instructions.

The function that they accept requires the input of AuthenticationStateData, which means it’s already been deserialized.

But the deserializer only works on AuthenticationStateData. I tried deriving from it, but I can’t seem to configure a Json converter to handle it, especially since System.Json.Text wants me to put an attribute on the parent class (AFAIK).

So that died pretty fast.

dotnet 8 approach
Back to the drawing board, I set up the Persistent/Persisting twins.

In this case the webassembly client is getting the data properly, so I know that I am creating, serializing and deserializing all the identities just fine.

What’s not working is the server side. It looks like OnAuthenticationStateChanged is getting called on the server multiple times and the last time through my additional identities are not there.

I thought I’d ask here because maybe I’m missing something.

My only alternative is a pretty ugly hack of AuthenticationStateData to make it hold all the data somehow and then more ugliness on the client side to break it up.

TIA for any guidance.