Closed dazinator closed 6 years ago
Ah damn, I missed the overload of UserStore that takes the type I needed.
I should have declared it like this:
public class DennisUserStore : UserStore<DennisUser, IdentityRole<int>, DennisContext, int, IdentityUserClaim<int>, IdentityUserRole<int>, DennisUserLogin, IdentityUserToken<int>, IdentityRoleClaim<int>>, IDennisUserStore
{
@dazinator For future reference, see https://docs.microsoft.com/en-us/aspnet/core/security/authentication/customize_identity_model?view=aspnetcore-2.1
Feedback on the doc appreciated.
I'm using the EF stores.
The only change I'd like to make is to add a column to the
AspNetUserLogins
table so that I can also store the refresh token associated with the external login. I think adding a column to an EF model should be fairly straightforward, and it was, but then getting identity to work with it is turning out to be a bit painful :-)I derived my own entity from
IdentityUserLogin<int>
and added the additional property:And therefore had to derive my own
IdentityDbContext
, passing in that replacement type:I was able to then add a new ef migration, and apply that, and I can see the additional column in the database - great.
Next I needed to be able to set this new property. So I had to find the locations where a new
IdentityUserLogin
entity is created, so that I could also set my additional property before its saved.Unfortunately the
UserStore
seems to create this entity, and the there is nowhere in the existing API where I could pass an additional value to it (i.e referesh token). Therefore overriding any existing method on UserStore or UserManager wouldn't cater for my scenario. So I had to add some additional method to UserManager and UserStore that also took a "refresh token":and
UserManager
:So far this is a lot of work in order to be able to add one property to this entity but I thought I was close.
I changed the razor UI code to call the new method on my UserManager instead which takes the refresh token,
Now when I run the app, when attempting an external login, I get the following error:
It seems something about the store is still specifically looking for
IdentityUserLogin<int>
which isn't part of my model anymore - because I am using my own derived typeDennisUserLogin
. However it doesn't appear I can inform the user store of that.. What am I missing?