Example #1
0
        public async Task <IActionResult> TwoFactorAuth(TwoFactorAuthModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.FindByNameAsync(model.Email);

            if (user == null)
            {
                AddUserNotFoundModelState();
                return(View(model));
            }

            try
            {
                await user.RespondToSmsMfaAuthAsync(
                    new RespondToSmsMfaRequest {
                    SessionID = user.SessionTokens.IdToken,
                    MfaCode   = model.Code
                });
            }
            catch (Exception e)
            {
                ModelState.AddModelError("MFAFailed", $"Failed to validate the provided code. Err: {e.Message}");
                return(View(model));
            }

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Post(TwoFactorAuthModel model)
        {
            var result = _confirmationService.TryAndConfirmCode(model);

            if (result.Success)
            {
                _logUserIn.Login(result.User, false); //TODO: pass this over
                return(Redirect(result.ReturnUrl));
            }
            return(_uniquePageService.RedirectTo <TwoFactorCodePage>(new { result.ReturnUrl }));
        }
 public void AddOptionalParamsRange(TwoFactorAuthModel source)
 {
     if (!string.IsNullOrWhiteSpace(source.GoogleAuthenticatorCode))
     {
         Add("GoogleAuthenticatorCode", source.GoogleAuthenticatorCode);
     }
     if (!string.IsNullOrWhiteSpace(source.Otp))
     {
         Add("Otp", source.Otp);
     }
 }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="authModel"></param>
        /// <param name="optionalParams"></param>
        /// <returns></returns>
        public ApiResponse <LoginRadiusApiResponse <LoginRadiusUserIdentity> > VerifyTwoFactorAuthentication(
            TwoFactorAuthModel authModel, LoginRadiusApiOptionalParams optionalParams)
        {
            Validate(new ArrayList {
                authModel.GoogleAuthenticatorCode, authModel.Otp
            });
            var additionalQueryParams = new QueryParameters
            {
                ["SecondFactorAuthenticationToken"] = authModel.SecondFactorAuthenticationToken,
                ["googleAuthenticatorCode"]         = authModel.GoogleAuthenticatorCode,
                ["otp"]            = authModel.Otp,
                ["smsTemplate2FA"] = optionalParams.SmsTemplate2Fa
            };


            return(ConfigureAndExecute <LoginRadiusApiResponse <LoginRadiusUserIdentity> >(
                       RequestType.Authentication, HttpMethod.Get,
                       "login/2FA/Verification",
                       additionalQueryParams));
        }
Example #5
0
        TwoFactorLoginAuthentication(string twoFactorAuthenticationToken,
                                     TwoFactorAuthModel twoFactorLoginAuthentication,
                                     LoginRadiusApiOptionalParams optionalParams)
        {
            Validate(new ArrayList {
                twoFactorAuthenticationToken
            });
            var additionalQueryParams = new QueryParameters
            {
                { "TwoFactorAuthenticationToken", twoFactorAuthenticationToken }
            };

            additionalQueryParams.AddOptionalParamsRange(twoFactorLoginAuthentication);
            additionalQueryParams.AddOptionalParamsRange(optionalParams);
            return
                (ConfigureAndExecute
                 <LoginResponse <LoginRadiusUserIdentity> >(
                     RequestType.Authentication,
                     HttpMethod.Get, _resoucePath.ChildObject("2FA/verification").ToString(), additionalQueryParams));
        }
        public ActionResult Show(TwoFactorCodePage page, TwoFactorAuthModel model)
        {
            ModelState.Clear();
            var status = _confirmationService.GetStatus();

            switch (status)
            {
            case TwoFactorStatus.Valid:
                ViewData["2fa-model"] = model;
                return(View(page));

            case TwoFactorStatus.Expired:
                TempData["login-model"] = new LoginModel {
                    Message = "Two-factor token expired, please try again."
                };
                return(_uniquePageService.RedirectTo <LoginPage>());

            default:
                return(_uniquePageService.RedirectTo <LoginPage>());
            }
        }
Example #7
0
        public Confirm2FAResult TryAndConfirmCode(TwoFactorAuthModel model)
        {
            var result = new Confirm2FAResult {
                ReturnUrl = model.ReturnUrl
            };

            if (!(_sessionState[SetVerifiedUserData.CurrentUserKey] is Guid guid))
            {
                return(result);
            }

            var user = _userLookup.GetUserByGuid(guid);

            if (user == null)
            {
                return(result);
            }

            if (user.TwoFactorCodeExpiry == null || user.TwoFactorCodeExpiry < CurrentRequestData.Now)
            {
                return(result);
            }

            var code = model.Code?.Trim();

            if (StringComparer.OrdinalIgnoreCase.Equals(user.TwoFactorCode, code))
            {
                result.Success = true;
                result.User    = user;
            }
            else
            {
                result.Message = "The code you entered was invalid.";
            }
            return(result);
        }
Example #8
0
        public ActionResult OTPAuthentication(TwoFactorAuthModel objtwoFactorModel)
        {
            List <OTPConfigurationDTO> lstOTPConfiguration = null;
            LoginUserDetails           objLoginUserDetails = null;
            int    OTPDigits                  = 0;
            bool   IsAlphaNumeric             = false;
            int    OTPConfigMasterID          = 1;
            int    UserInfoID                 = 0;
            string EmailId                    = string.Empty;
            int    OTPExpirationTimeInSeconds = 0;
            string GeneratedOTP               = string.Empty;
            string userLoginId                = string.Empty;
            int    returnResult               = 0;

            try
            {
                objLoginUserDetails = (LoginUserDetails)Common.Common.GetSessionValue(ConstEnum.SessionValue.UserDetails);
                userLoginId         = objLoginUserDetails.UserName;
                using (TwoFactorAuthSL objOTPAuthDAL = new TwoFactorAuthSL())
                {
                    lstOTPConfiguration = objOTPAuthDAL.GetOTPConfiguration(objLoginUserDetails.CompanyDBConnectionString);
                    foreach (var OTPConfig in lstOTPConfiguration)
                    {
                        OTPDigits                  = OTPConfig.OTPDigits;
                        IsAlphaNumeric             = OTPConfig.IsAlphaNumeric;
                        OTPConfigMasterID          = OTPConfig.OTPConfigurationSettingMasterID;
                        OTPExpirationTimeInSeconds = OTPConfig.OTPExpirationTimeInSeconds;
                    }

                    lstOTPConfiguration = objOTPAuthDAL.GetUserDeatailsForOTP(objLoginUserDetails.CompanyDBConnectionString, userLoginId);
                    foreach (var usrDetails in lstOTPConfiguration)
                    {
                        UserInfoID = usrDetails.UserInfoId;
                        EmailId    = usrDetails.EmailID;
                    }
                    if (objtwoFactorModel.OTPCode.Length == OTPDigits)
                    {
                        returnResult = objOTPAuthDAL.ValidateOTPDetails(objLoginUserDetails.CompanyDBConnectionString, OTPConfigMasterID, UserInfoID, objtwoFactorModel.OTPCode);
                    }
                    else
                    {
                        returnResult = 3;
                    }
                }
                if (returnResult == 1)
                {
                    Session["loginStatus"] = 1;
                    Session["TwoFactor"]   = 0;
                    return(RedirectToAction("Index", "Home", new { acid = Convert.ToString(0), calledFrom = "Login" }));
                }
                else if (returnResult == 2)
                {
                    objLoginUserDetails.SuccessMessage = null;
                    objLoginUserDetails.ErrorMessage   = Common.Common.getResource("tfa_msg_61004");
                    Common.Common.SetSessionValue(ConstEnum.SessionValue.UserDetails, objLoginUserDetails);
                    Common.Common.WriteLogToFile(Common.Common.getResource("tfa_msg_61004"));
                    return(RedirectToAction("Index", "TwoFactorAuth", new { acid = Convert.ToString(0), calledFrom = "" }));
                }
                else if (returnResult == 3)
                {
                    objLoginUserDetails.SuccessMessage = null;
                    objLoginUserDetails.ErrorMessage   = Common.Common.getResource("tfa_msg_61003");
                    Common.Common.SetSessionValue(ConstEnum.SessionValue.UserDetails, objLoginUserDetails);
                    Common.Common.WriteLogToFile(Common.Common.getResource("tfa_msg_61003"));
                    return(RedirectToAction("Index", "TwoFactorAuth", new { acid = Convert.ToString(0), calledFrom = "" }));
                }
                else
                {
                    return(RedirectToAction("Index", "TwoFactorAuth", new { acid = Convert.ToString(0), calledFrom = "" }));
                }
            }
            catch (Exception exp)
            {
                Common.Common.WriteLogToFile("Exception occurred ", System.Reflection.MethodBase.GetCurrentMethod(), exp);
                ClearAllSessions();
                return(RedirectToAction("Login", "Account"));
            }
            finally
            {
                objLoginUserDetails = null;
            }
        }