Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizing Identity UserManager and RoleManager #21

Open
dogaanismail opened this issue Aug 22, 2020 · 0 comments
Open

Customizing Identity UserManager and RoleManager #21

dogaanismail opened this issue Aug 22, 2020 · 0 comments
Milestone

Comments

@dogaanismail
Copy link

dogaanismail commented Aug 22, 2020

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.

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.

How can I handle it ?

Best Regards

@MaceWindu MaceWindu added this to the Release 3.1.0 milestone Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants