I have been trying to use UserManager and RoleManager. I have implemented my identity classes that have int primary key.
For instance, when I would like to use UserManager FindByIdAsync method, it is still required string userId parameter, but I want to user int parameter. How can I change this ? Actually, I have not customized UserManager ord UserStore before.
Here is my AppUser class.
public class AppUser : IdentityUser<int>, IEntity
{
[Required, Identity]
[Key]
public override int Id { get => base.Id; set => base.Id = value; }
public DateTime CreatedDate { get; set; }
public DateTime? ModifiedDate { get; set; }
public int? CreatedBy { get; set; }
public int? ModifiedBy { get; set; }
public int? StatusId { get; set; }
}
Here is my AddLinqToDBStores implementation.
``
/// <summary>
/// Adds authentication service
/// </summary>
/// <param name="services">Collection of service descriptors</param>
public static void AddDevPlatformAuthentication(this IServiceCollection services, IConfiguration configuration)
{
services.AddIdentity<AppUser, AppRole>(options =>
{
options.Password.RequireDigit = true;
options.Password.RequiredLength = 4;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = false;
options.User.RequireUniqueEmail = true;
options.SignIn.RequireConfirmedEmail = false;
//TODO
//options.User.RequireUniqueEmail = true;
//options.Lockout.MaxFailedAccessAttempts = 5;
//options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(3);
}).AddLinqToDBStores<int, AppUserClaim, AppUserRole, AppUserLogin, AppUserToken, AppRoleClaim>(new
IdentityConnectionFactory(new SqlServerDataProvider(ProviderName.SqlServer, SqlServerVersion.v2017), "SqlServerIdentity", DataSettingsManager.LoadSettings().ConnectionString))
.AddUserStore<LinqToDB.Identity.UserStore<int, AppUser, AppRole, AppUserClaim, AppUserRole, AppUserLogin, AppUserToken>>()
.AddUserManager<UserManager<AppUser>>()
.AddRoleManager<RoleManager<AppRole>>()
.AddDefaultTokenProviders();
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
// Uncomment the following lines to enable logging in with third party login providers
JwtTokenDefinitions.LoadFromConfiguration(configuration);
services.ConfigureJwtAuthentication();
services.ConfigureJwtAuthorization();
}
_userManager.FindByIdAsync() as I said, I need to use an int parameter for all userManager method.
Hello,
I have been trying to use UserManager and RoleManager. I have implemented my identity classes that have int primary key.
For instance, when I would like to use UserManager FindByIdAsync method, it is still required string userId parameter, but I want to user int parameter. How can I change this ? Actually, I have not customized UserManager ord UserStore before.
Here is my AppUser class.
Here is my AddLinqToDBStores implementation.
_userManager.FindByIdAsync() as I said, I need to use an int parameter for all userManager method.
How can I handle it ?
Best Regards