UserStore for ASP.NET Core Identity

Based on the implementation published on GitHub , I created my own UserStore and RoleStore that do not use the Entity Framework (currently I only need a simple list of users in memory before I join the real database). To do this, I had to change the registration. I wrote my own IdentityEntityFrameworkBuilderExtensions without DbContext and with TryAddSingleton instead of TryAddScoped, so as soon as the initialized list of users can last through the life of the application. The problem is that the Dispose method is called so many times ... I don't order anything, but there are so many calls. This is because I created singletonUserStore and RoleStore , although everything else works the way they were covered?

Secondly, what is the minimum required to run a working UserStore ?

danludwig wrote you only need IUserStore and IUserPasswordStore, and this is very likely because I made a repository that implements these two interfaces, and RoleStore with IRoleStore, and it seems to work. I also made RoleStore because of the part services.AddIdentity<ApplicationUser, IdentityRole>()in the launch class. I used the Entity Framework authorization template for the main ASP.NET web application (with separate user accounts).

Arve Sistad and Anderson Matos wrote that you need these 8:

  • IUserStore<TUser>
  • IUserPasswordStore<TUser>
  • IUserTwoFactorStore<TUser>
  • IUserClaimStore<TUser>
  • IRoleStore<TRole>
  • IUserSecurityStampStore<TUser, string>
  • IUserRoleStore<TUser, string>
  • UserManager<TUser>

Entity Framework, , UserStore RoleStore, ( GitHub):

  • IUserLoginStore,
  • IUserRoleStore,
  • IUserClaimStore,
  • IUserPasswordStore,
  • IUserSecurityStampStore,
  • IUserEmailStore,
  • IUserLockoutStore,
  • IUserPhoneNumberStore,
  • IQueryableUserStore,
  • IUserTwoFactorStore,
  • IUserAuthenticationTokenStore

  1. IQueryableRoleStore,
  2. IRoleClaimStore

UserStore RoleStore Entity Framework, :

  • IQueryableUserStore,
  • IUserPasswordStore,
  • IUserSecurityStampStore,
  • IUserLockoutStore,
  • IUserTwoFactorStore,
  • IUserRoleStore,
  • IUserClaimStore

, , IRoleStore, Dispose. Get... . , IQueryableUserStore, IUserPasswordStore, IUserSecurityStampStore IUserLockoutStore, ?

EDIT:

-EF UserStore : :

public class MyUserStore<TUser> :
    IQueryableUserStore<TUser>,
    IUserPasswordStore<TUser>,
    IUserSecurityStampStore<TUser>
    where TUser : MyIdentity
{
    private List<TUser> _identities = new List<TUser>();
    CreateAsync(...)
    FindByIdAsync(...)
    FindByNameAsync(...)
    GetPasswordHashAsync(...)
    GetSecurityStampAsync(...)
    GetUserIdAsync(...)
    GetUserNameAsync(...)
    SetNormalizedUserNameAsync(...)
    SetPasswordHashAsync(...)
    SetSecurityStampAsync(...)
}

, , - setter UserStore. Identity:

    public async Task SetNormalizedUserNameAsync(TUser user, string normalizedName, CancellationToken cancellationToken)
    {
        cancellationToken.ThrowIfCancellationRequested();
        ThrowIfDisposed();
        if (user == null)
        {
            throw new ArgumentNullException("user");
        }
        user.NormalizedUserName = normalizedName;
        await UpdateAsync(user, cancellationToken);
    }

? ? , , , , SetPasswordHashAsync CreateAsync...: P

+4

Source: https://habr.com/ru/post/1663767/


All Articles