Example #1
0
        public static void Apply(this IdentityOptions o, IdentityOptionsExtended x)
        {
            o.ClaimsIdentity.RoleClaimType          = x.ClaimsIdentity.RoleClaimType;
            o.ClaimsIdentity.SecurityStampClaimType = x.ClaimsIdentity.SecurityStampClaimType;
            o.ClaimsIdentity.UserIdClaimType        = x.ClaimsIdentity.UserIdClaimType;
            o.ClaimsIdentity.UserNameClaimType      = x.ClaimsIdentity.UserNameClaimType;

            o.Stores.ProtectPersonalData = x.Stores.ProtectPersonalData;
            o.Stores.MaxLengthForKeys    = x.Stores.MaxLengthForKeys;

            o.User.AllowedUserNameCharacters = x.User.AllowedUserNameCharacters;
            o.User.RequireUniqueEmail        = x.User.RequireUniqueEmail;

            o.Lockout.AllowedForNewUsers      = x.Lockout.AllowedForNewUsers;
            o.Lockout.DefaultLockoutTimeSpan  = x.Lockout.DefaultLockoutTimeSpan;
            o.Lockout.MaxFailedAccessAttempts = x.Lockout.MaxFailedAccessAttempts;

            o.Password.RequireDigit           = x.Password.RequireDigit;
            o.Password.RequireLowercase       = x.Password.RequireLowercase;
            o.Password.RequireNonAlphanumeric = x.Password.RequireNonAlphanumeric;
            o.Password.RequireUppercase       = x.Password.RequireUppercase;
            o.Password.RequiredLength         = x.Password.RequiredLength;
            o.Password.RequiredUniqueChars    = x.Password.RequiredUniqueChars;

            o.Tokens.AuthenticatorTokenProvider     = x.Tokens.AuthenticatorTokenProvider;
            o.Tokens.ChangeEmailTokenProvider       = x.Tokens.ChangeEmailTokenProvider;
            o.Tokens.ChangePhoneNumberTokenProvider = x.Tokens.ChangePhoneNumberTokenProvider;
            o.Tokens.EmailConfirmationTokenProvider = x.Tokens.EmailConfirmationTokenProvider;
            o.Tokens.PasswordResetTokenProvider     = x.Tokens.PasswordResetTokenProvider;
            o.Tokens.ProviderMap = x.Tokens.ProviderMap;

            o.SignIn.RequireConfirmedEmail       = x.SignIn.RequireConfirmedEmail;
            o.SignIn.RequireConfirmedPhoneNumber = x.SignIn.RequireConfirmedPhoneNumber;
        }
Example #2
0
File: Add.cs Project: qiqi545/HQ
        private static void MigrateToLatest(string connectionString, IdentityOptionsExtended identityOptions)
        {
            var runner = new SqliteMigrationRunner(connectionString);

            if (identityOptions.Stores.CreateIfNotExists)
            {
                runner.CreateDatabaseIfNotExists();
            }

            if (identityOptions.Stores.MigrateOnStartup)
            {
                runner.MigrateUp(typeof(CreateIdentitySchema).Assembly, typeof(CreateIdentitySchema).Namespace);
            }
        }
Example #3
0
        private static void MigrateToLatest <TKey>(string connectionString, IdentityOptionsExtended identityOptions,
                                                   SqliteOptions options) where TKey : IEquatable <TKey>
        {
            var runner = new MigrationRunner(connectionString, options);

            if (identityOptions.Stores.CreateIfNotExists)
            {
                runner.CreateDatabaseIfNotExistsAsync(CancellationToken.None).Wait();
            }

            if (identityOptions.Stores.MigrateOnStartup)
            {
                runner.MigrateUp(CancellationToken.None);
            }
        }
Example #4
0
        public static IdentityBuilder AddIdentityCoreExtended <TUser, TRole, TTenant, TKey>(this IServiceCollection services,
                                                                                            Action <IdentityOptions> configureIdentity = null,
                                                                                            Action <IdentityOptionsExtended> configureIdentityExtended = null)
            where TUser : IdentityUserExtended <TKey>
            where TRole : IdentityRoleExtended <TKey>
            where TTenant : IdentityTenant <TKey>
            where TKey : IEquatable <TKey>
        {
            /*
             *  services.AddOptions().AddLogging();
             *  services.TryAddScoped<IUserValidator<TUser>, UserValidator<TUser>>();
             *  services.TryAddScoped<IPasswordValidator<TUser>, PasswordValidator<TUser>>();
             *  services.TryAddScoped<IPasswordHasher<TUser>, PasswordHasher<TUser>>();
             *  services.TryAddScoped<ILookupNormalizer, UpperInvariantLookupNormalizer>();
             *  services.TryAddScoped<IdentityErrorDescriber>();
             *  services.TryAddScoped<IUserClaimsPrincipalFactory<TUser>, UserClaimsPrincipalFactory<TUser>>();
             *  services.TryAddScoped<UserManager<TUser>, UserManager<TUser>>();
             *  if (setupAction != null)
             *    services.Configure<IdentityOptions>(setupAction);
             *  return new IdentityBuilder(typeof (TUser), services);
             */
            var identityBuilder = services.AddIdentityCore <TUser>(o =>
            {
                var x = new IdentityOptionsExtended(o);
                Defaults(x);
                configureIdentityExtended?.Invoke(x);
                o.Apply(x);
            });

            if (configureIdentityExtended != null)
            {
                services.Configure(configureIdentityExtended);
            }

            if (configureIdentity != null)
            {
                services.Configure(configureIdentity);
            }

            identityBuilder.AddDefaultTokenProviders();
            identityBuilder.AddPersonalDataProtection <NoLookupProtector, NoLookupProtectorKeyRing>();
            identityBuilder.Services.AddSingleton <IPersonalDataProtector, DefaultPersonalDataProtector>();

            services.AddScoped <IEmailValidator <TUser>, DefaultEmailValidator <TUser> >();
            services.AddScoped <IPhoneNumberValidator <TUser>, DefaultPhoneNumberValidator <TUser> >();
            services.AddScoped <IUsernameValidator <TUser>, DefaultUsernameValidator <TUser> >();

            var validator = services.SingleOrDefault(x => x.ServiceType == typeof(IUserValidator <TUser>));
            var removed   = services.Remove(validator);

            Debug.Assert(validator != null);
            Debug.Assert(removed);

            services.AddScoped <IUserValidator <TUser>, UserValidatorExtended <TUser> >();
            services.AddScoped <ITenantValidator <TTenant, TUser, TKey>, TenantValidator <TTenant, TUser, TKey> >();

            services.AddScoped <IUserService <TUser>, UserService <TUser, TKey> >();
            services.AddScoped <ITenantService <TTenant>, TenantService <TTenant, TUser, TKey> >();
            services.AddScoped <IRoleService <TRole>, RoleService <TRole, TKey> >();
            services.AddScoped <ISignInService <TUser>, SignInService <TUser, TKey> >();

            services.AddSingleton <IServerTimestampService, LocalServerTimestampService>();

            return(identityBuilder);
        }