Example #1
0
        private OTPResult ComputeOTPResult(string otpString, DateTime utcDateTime)
        {
            var dateTime = utcDateTime;

            var second = dateTime.Second;

            if (second >= 15 && second < 45)
            {
                dateTime = dateTime.AddSeconds(-(second - 15));
            }
            else if (second >= 45 && second <= 59)
            {
                dateTime = dateTime.AddSeconds(-(second - 45));
            }
            else if (second >= 0 && second < 15)
            {
                dateTime = dateTime.AddSeconds(-second - 15);
            }

            var validUntil  = dateTime.AddSeconds(this._settings.TimeStep);
            var secondsLeft = (int)(validUntil - utcDateTime).TotalSeconds;

            var otpResult = new OTPResult
            {
                OTPPassword      = otpString,
                ValidFrom        = dateTime,
                ValidUntil       = dateTime.AddSeconds(this._settings.TimeStep),
                ValidSecondsLeft = secondsLeft
            };

            return(otpResult);
        }
        /// <summary>
        /// Use this endpoint and HTTP method to Request a OTP Verification to a previously created OTP.
        /// </summary>
        /// <param name="caseId">
        /// CaseId - This is returned in the Response Header when a Trustev Case is created.
        /// </param>
        /// <param name="request">
        /// Status Request Object
        /// </param>
        /// <returns>
        /// </returns>
        public static async Task <OTPResult> PutOtpAsync(string caseId, OTPResult request)
        {
            var uri = string.Format(Constants.UriOtp, BaseUrl, caseId);

            var digitalAuthenticationResult = await PerformHttpCallAsync <OTPResult>(uri, HttpMethod.Put, request, true, HttpRequestTimeout);

            return(digitalAuthenticationResult);
        }
Example #3
0
 public async Task <OTPResult> FetchOTPAsync(HttpClient client, string otpUrl)
 {
     try
     {
         using (var rsp = await client.GetAsync(otpUrl))
         {
             return(OTPResult.From(rsp.Content.ReadAsStringAsync().Result));
         }
     }
     catch { }
     return(new OTPResult());
 }
Example #4
0
        public OTPResultViewModelBuilder FromOTPResult(OTPResult otpResult)
        {
            this._viewModel.Successful = otpResult != null;

            if (otpResult != null)
            {
                this.WithValidUntil(otpResult.ValidUntil)
                .WithOTPPassword(otpResult.OTPPassword)
                .WithValidFrom(otpResult.ValidFrom)
                .WithValidSecondsLeft(otpResult.ValidSecondsLeft);
            }

            return(this);
        }
        public async Task SentOtpAsync()
        {
            Case sampleCase = GenerateSampleCase();
            Case returnCase = await ApiClient.PostCaseAsync(sampleCase);

            var detailedDecision = await ApiClient.GetDetailedDecisionAsync(returnCase.Id);

            Assert.IsTrue(detailedDecision.Authentication.OTP.Status == Enums.OTPStatus.Offered);

            DigitalAuthenticationResult auth    = GenerateDigitalAuthenticationResult();
            OTPResult checkAuthenticationResult = await ApiClient.PostOtpAsync(returnCase.Id, auth.OTP);

            Assert.IsTrue(checkAuthenticationResult.Status == Enums.OTPStatus.InProgress);
        }
        public async Task VerifyOtpAsync()
        {
            Case sampleCase = GenerateSampleCase();
            Case returnCase = await ApiClient.PostCaseAsync(sampleCase);

            var detailedDecision = await ApiClient.GetDetailedDecisionAsync(returnCase.Id);

            Assert.IsTrue(detailedDecision.Authentication.OTP.Status == Enums.OTPStatus.Offered);

            DigitalAuthenticationResult auth = GenerateDigitalAuthenticationResult();
            var checkAuthenticationResult    = await ApiClient.PostOtpAsync(returnCase.Id, auth.OTP);

            Assert.IsTrue(checkAuthenticationResult.Status == Enums.OTPStatus.InProgress);

            // if you want this to pass then change the passcode to the code received from the sms
            var verificationCode = new OTPResult()
            {
                Passcode = "1234", Timestamp = DateTime.Now
            };
            var checkPasswordDigitalAuthenticationResult = await ApiClient.PutOtpAsync(returnCase.Id, verificationCode);

            Assert.IsTrue(checkPasswordDigitalAuthenticationResult.Status == Enums.OTPStatus.Fail);
        }