-
Notifications
You must be signed in to change notification settings - Fork 864
Make Roles optional at the Microsoft.Extensions.Identity layer #1269
Comments
@HaoK do you always need to configure in |
Its an optional thing, I just was showing it to make it obvious that was where you will can opt into/out of things. AddEntityFrameworkStores() would do something by default appropriately... |
But its likely there will be ways to mismatch things, like calling AddRoles() and then doing storeOptions.SupportsRoles = false... We won't be able to block all of those, but it should be easy to validate |
Basically misconfiguring storeOptions will cause manager apis to throw if they end up calling into store functionality that they disable |
Also related to #581 |
After chatting with @ajcvickers today we agreed that this is something important to do in 2.0, some nice sideffects that fell out of the refactoring/exploring this. we can nuke all of the entities on TUser/TRole except for TKey... That cleans things up quite a bit. |
@blowdart @Eilon @DamianEdwards
Could you please clarify a bit more what this means? |
We had a bunch of generics that were on the base POCOs that were only needed for the navigation properties, see: https://github.com/aspnet/Identity/blob/dev/src/Microsoft.Extensions.Identity.Stores/IdentityUser.cs#L54 There will only be TKey now. |
To clarify the plan, we are leaving the existing AddIdentity alone that lives in Microsoft.AspNet.Identity, that will behave the same and add the same old user + roles scheme. Since we are adding a new public AddIdentityCore API in Microsoft.Extensions.Identity.Core anyways, we might as well expose it the 'right way', meaning Users are the only required entity, with Roles being an add on. |
Ah, I was curious how those extra generic parameters got used since they don't appear on any of the type members. When you say they are currently needed for the navigation properties, what does that mean? Aren't navigation properties typically represented as properties on the type? Does EF Core do something special with the extra generic parameters in this case? Or does Identity? Regardless, not having those extra generic parameters sounds like a good change. |
StoreOptions are gone, so there's none of that complexity. There will be a new UserStore base class that doesn't implement any of the Role interfaces, that will be what is used when roles isn't enabled. Otherwise, the usual roles + user store will be used. We'll actually have proper base classes for 2.0 that do not have a TRole at all (IdentityDbContext/UserStore) |
The POCOs used to live inside of EF Core, and they had navigation properties. I removed them as part of the move to Extensions for preview 2. This is finishing the rest of the move as there's no way to actually use Extensions.Identity today without AspNet.Identity. |
@divega @ajcvickers Well, there's a tiny complication to removing the generics off IdentityUser... turns out we were using them to use reflection to automagically register the correct UserStore so they didn't have to manually add their own We added the smarts to infer generics in 1.1. We do have another generic type with the same information, the IdentityDbContext, but there's no hard requirement that they use our DbContext, as any DbContext works today. But I think this would cover the majority of use cases, so we'd be only impacting customers relying on the custom poco AddEntityFrameworkStores magic who were using their own DbContext that didn't derive from IdentityDbContext.... Thoughts? |
@HaoK This was a breaking change for me and I'd like to add the functionality back in. The migration docs here says:
I was using the roles collection on the user and the users collection on the role, but they used to operate without needing to traverse the link table. How, specifically, can I restore that exact functionality? My |
You need the navigation property to be pointing at TUserRole, which is what it was in 1.x: In 1.x: IdentityDbContext.OnModelCreating:
In 2.x:
|
Thanks @HaoK - for some reason I had in my head that the many to many relationship was exposed through the navigation properties without having to go through the link table, I guess due to the name of the properties. Appreciate the clarification. |
@HaoK , I think that will be for 2.1 Milestone (?) |
High level idea is to enable something akin to:
Related to #651
I think this should be safe to do in 2.1, but we might want to consider doing something like this in RTM (as this is really finishing what we started in 651)
Would be equivalent to today's (which we would still support):
The text was updated successfully, but these errors were encountered: