Example #1
0
        /// <summary>
        /// Adds the <see cref="ExtendedPhoneNumberTokenProvider{TUser}"/> as a default phone provider.
        /// </summary>
        /// <param name="builder">Helper functions for configuring identity services.</param>
        /// <param name="configure"></param>
        /// <returns>The configured <see cref="IdentityBuilder"/>.</returns>
        public static IdentityBuilder AddExtendedPhoneNumberTokenProvider(this IdentityBuilder builder, Action <TotpOptions> configure = null)
        {
            builder.Services.AddDefaultTotpService(configure);
            var providerType = typeof(ExtendedPhoneNumberTokenProvider <>).MakeGenericType(builder.UserType);

            builder.AddTokenProvider(TokenOptions.DefaultPhoneProvider, providerType);
            return(builder);
        }
        /// <summary>
        /// Adds the default token providers used to generate tokens for reset passwords, change email
        /// and change telephone number operations, and for two factor authentication token generation.
        /// </summary>
        /// <param name="builder">The current <see cref="IdentityBuilder"/> instance.</param>
        /// <returns>The current <see cref="IdentityBuilder"/> instance.</returns>
        public static IdentityBuilder AddDefaultTokenProviders(this IdentityBuilder builder)
        {
            var userType = builder.UserType;
            var dataProtectionProviderType = typeof(DataProtectorTokenProvider <>).MakeGenericType(userType);
            var phoneNumberProviderType    = typeof(PhoneNumberTokenProvider <>).MakeGenericType(userType);
            var emailTokenProviderType     = typeof(EmailTokenProvider <>).MakeGenericType(userType);
            var authenticatorProviderType  = typeof(AuthenticatorTokenProvider <>).MakeGenericType(userType);

            return(builder.AddTokenProvider(TokenOptions.DefaultProvider, dataProtectionProviderType)
                   .AddTokenProvider(TokenOptions.DefaultEmailProvider, emailTokenProviderType)
                   .AddTokenProvider(TokenOptions.DefaultPhoneProvider, phoneNumberProviderType)
                   .AddTokenProvider(TokenOptions.DefaultAuthenticatorProvider, authenticatorProviderType));
        }
Example #3
0
        public static IdentityBuilder AddYubikeyOTPTokenProvider(this IdentityBuilder builder, Action <YubikeyOTPOptions> setupAction)
        {
            var userType          = builder.UserType;
            var tokenProviderType = typeof(YubikeyOTPTokenProvider <>).MakeGenericType(userType);
            var retval            = builder.AddTokenProvider(YubikeyOTPOptions.ProviderName, tokenProviderType);

            var services = builder.Services;

            services.AddSingleton <IConfigureOptions <YubikeyOTPOptions>, YubikeyOTPOptionsSetup>();
            if (setupAction != null)
            {
                services.Configure(setupAction);
            }

            services.AddTransient <YubikeyOTPValidator>();

            return(retval);
        }