Example #1
0
        /// <summary>
        /// Validates whether a verifyCode is valid to use with the TeleSign API.
        /// Null is valid and indicates the API should generate the code itself,
        /// empty strings are not valid, any non-digit characters are not valid
        /// and leading zeros are not valid.
        /// </summary>
        /// <param name="verifyCode">The code to verify.</param>
        public virtual void ValidateCodeFormat(string verifyCode)
        {
            if (verifyCode == null)
            {
                // When the code is null we generate it, so this is valid.
                return;
            }

            // Empty code is never valid
            CheckArgument.NotEmpty(verifyCode, "verifyCode");

            // Leading zeros are not allowed.
            if (verifyCode[0] == '0')
            {
                string message = string.Format(
                    "Verify code '{0}' must not have leading zeroes.",
                    verifyCode);

                throw new ArgumentException(message);
            }

            foreach (char c in verifyCode)
            {
                // Only decimal digits are allowed 0-9.
                if (!Char.IsDigit(c))
                {
                    string message = string.Format(
                        "Verify code '{0}' must only contain decimal digits [0-9]",
                        verifyCode);

                    throw new ArgumentException(message);
                }
            }
        }
Example #2
0
        /////// <summary>
        /////// The TeleSign Verify Soft Token web service is a server-side component of the TeleSign AuthID application, and it allows you to authenticate your end users when they use the TeleSign AuthID application on their mobile device to generate a Time-based One-time Password (TOTP) verification code
        /////// </summary>
        /////// <param name="phoneNumber">The phone number for the Verify Soft Token request, including country code</param>
        /////// <param name="softTokenId">
        /////// The alphanumeric string that uniquely identifies your TeleSign soft token subscription
        /////// </param>
        /////// <param name="verifyCode">
        /////// The verification code received from the end user
        /////// </param>
        /////// <returns>The raw JSON response from the REST API.</returns>
        ////public string SoftTokenRaw(
        ////            string phoneNumber,
        ////            string softTokenId = null,
        ////            string verifyCode = null)
        ////{
        ////    phoneNumber = this.CleanupPhoneNumber(phoneNumber);

        ////    if (softTokenId == null)
        ////    {
        ////        softTokenId = string.Empty;
        ////    }

        ////    if (verifyCode == null)
        ////    {
        ////        verifyCode = string.Empty;
        ////    }

        ////    Dictionary<string, string> args = ConstructVerifyArgs(
        ////                VerificationMethod.SoftToken,
        ////                phoneNumber,
        ////                softTokenId,
        ////                verifyCode);

        ////    string resourceName = string.Format(
        ////                RawVerifyService.VerifyResourceFormatString,
        ////                VerificationMethod.SoftToken.ToString().ToLowerInvariant());

        ////    WebRequest request = this.ConstructWebMobileRequest(
        ////                resourceName,
        ////                "POST",
        ////                args);

        ////    return this.WebRequester.ReadResponseAsString(request);
        ////}

        /// <summary>
        /// The TeleSign Verify 2-Way SMS web service allows you to authenticate your users and verify user transactions via two-way Short Message Service (SMS) wireless communication. Verification requests are sent to user’s in a text message, and users return their verification responses by replying to the text message.
        /// </summary>
        /// <param name="phoneNumber">The phone number for the Verify Soft Token request, including country code</param>
        /// <param name="message">
        /// The text to display in the body of the text message. You must include the $$CODE$$ placeholder for the verification code somewhere in your message text. TeleSign automatically replaces it with a randomly-generated verification code
        /// </param>
        /// <param name="validityPeriod">
        /// This parameter allows you to place a time-limit on the verification. This provides an extra level of security by restricting the amount of time your end user has to respond (after which, TeleSign automatically rejects their response). Values are expressed as a natural number followed by a lower-case letter that represents the unit of measure. You can use 's' for seconds, 'm' for minutes, 'h' for hours, and 'd' for days
        /// </param>
        /// <param name="useCaseId"></param>
        /// <returns>The raw JSON response from the REST API.</returns>
        public string TwoWaySmsRaw(
            string phoneNumber,
            string message,
            string validityPeriod = "5m",
            string useCaseId      = RawVerifyService.DefaultUseCaseId)
        {
            CheckArgument.NotEmpty(message, "message");
            CheckArgument.NotNullOrEmpty(validityPeriod, "validityPeriod");

            phoneNumber = this.CleanupPhoneNumber(phoneNumber);

            Dictionary <string, string> args = ConstructVerifyArgs(
                VerificationMethod.TwoWaySms,
                phoneNumber,
                null,
                message,
                null,
                validityPeriod,
                useCaseId);

            string resourceName = string.Format(
                RawVerifyService.VerifyResourceFormatString,
                "two_way_sms");

            WebRequest request = this.ConstructWebRequest(
                resourceName,
                "POST",
                args);

            return(this.WebRequester.ReadResponseAsString(request));
        }
        /// <summary>
        /// Initializes a new instance of the Configuration class with different settings.
        /// </summary>
        /// <param name="basePath">The base API path.</param>
        /// <param name="applicationUserID">The ID of application user.</param>
        /// <param name="authenticationKey">The secret authentication key.</param>
        /// <param name="tempFolderPath">Temp folder path</param>
        /// <param name="timeout">HTTP connection timeout (in milliseconds)</param>
        /// <param name="userAgent">HTTP user agent</param>
        /// <param name="exceptionFactory">The factory of exceptions which are caused by service methods.</param>
        public Configuration(string basePath,
                             string applicationUserID,
                             string authenticationKey,
                             string tempFolderPath,
                             int timeout,
                             string userAgent,
                             ExceptionFactory exceptionFactory
                             )
        {
            _basePath          = CheckArgument.NotEmpty("basePath", basePath);
            _authenticationKey = CheckArgument.NotNull("authenticationKey", authenticationKey);
            _applicationUserID = CheckArgument.NotNull("applicationUserID", applicationUserID);
            _timeout           = timeout;
            _userAgent         = userAgent;

            if (!String.IsNullOrEmpty(tempFolderPath))
            {
                // check if the path contains directory separator at the end
                if (tempFolderPath[tempFolderPath.Length - 1] == Path.DirectorySeparatorChar)
                {
                    _tempFolderPath = tempFolderPath;
                }
                else
                {
                    _tempFolderPath = tempFolderPath + Path.DirectorySeparatorChar;
                }
            }
            else
            {
                _tempFolderPath = Path.GetTempPath();
            }

            // create the directory if it does not exist
            if (!Directory.Exists(_tempFolderPath))
            {
                Directory.CreateDirectory(_tempFolderPath);
            }

            if (exceptionFactory != null)
            {
                _exceptionFactory = exceptionFactory;
            }
            else
            {
                _exceptionFactory = DefaultExceptionFactory;
            }
        }