/// <summary>
 ///     Notify a user with a token from a specific user factor provider
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="userId"></param>
 /// <param name="twoFactorProvider"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static IdentityResult NotifyTwoFactorToken <TUser, TKey>(this UserManager <TUser, TKey> manager,
                                                                 TKey userId, string twoFactorProvider, string token)
     where TKey : IEquatable <TKey>
     where TUser : class, IUser <TKey>
 {
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     return(AsyncHelper.RunSync(() => manager.NotifyTwoFactorTokenAsync(userId, twoFactorProvider, token)));
 }
Exemple #2
0
        public virtual async Task <bool> SendTwoFactorCodeAsync(string provider,
                                                                CancellationToken cancellationToken = default(CancellationToken))
        {
            var twoFactorInfo = await RetrieveTwoFactorInfoAsync(cancellationToken);

            if (twoFactorInfo == null || twoFactorInfo.UserId == null)
            {
                return(false);
            }

            var user = await UserManager.FindByIdAsync(twoFactorInfo.UserId, cancellationToken);

            if (user == null)
            {
                return(false);
            }
            var token = await UserManager.GenerateTwoFactorTokenAsync(user, provider, cancellationToken);

            await UserManager.NotifyTwoFactorTokenAsync(user, provider, token, cancellationToken);

            return(await LogResultAsync(true, user));
        }
Exemple #3
0
        public virtual async Task <bool> SendTwoFactorCode(string provider)
        {
            var userId = await AuthenticationManager.RetrieveUserId();

            if (userId == null)
            {
                return(false);
            }

            var user = await UserManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(false);
            }
            var token = await UserManager.GenerateTwoFactorTokenAsync(user, provider);

            // See IdentityConfig.cs to plug in Email/SMS services to actually send the code
            await UserManager.NotifyTwoFactorTokenAsync(user, provider, token);

            return(true);
        }
Exemple #4
0
        public virtual async Task <bool> SendTwoFactorCodeAsync(string provider,
                                                                CancellationToken cancellationToken = default(CancellationToken))
        {
            var twoFactorInfo = await RetrieveTwoFactorInfoAsync(cancellationToken);

            if (twoFactorInfo == null || twoFactorInfo.UserId == null)
            {
                return(false);
            }

            var user = await UserManager.FindByIdAsync(twoFactorInfo.UserId, cancellationToken);

            if (user == null)
            {
                return(false);
            }
            var token = await UserManager.GenerateTwoFactorTokenAsync(user, provider, cancellationToken);

            // See IdentityConfig.cs to plug in Email/SMS services to actually send the code
            await UserManager.NotifyTwoFactorTokenAsync(user, provider, token, cancellationToken);

            return(true);
        }