Esempio n. 1
0
        /// <summary>
        /// Converts this contract into its <see cref="AuthenticationPrompt"/> model.
        /// </summary>
        /// <returns>The <see cref="AuthenticationPrompt"/> model.</returns>
        public AuthenticationPrompt ToAuthenticationPrompt()
        {
            AuthenticationPrompt authPrompt = new AuthenticationPrompt();

            authPrompt.AuthType = new AuthType(this.Type);
            JArray mfaArray = this.Prompt as JArray;

            if (authPrompt.AuthType == AuthType.Device)
            {
                JObject jobj    = this.Prompt as JObject;
                string  message = jobj["message"].Value <string>();
                authPrompt.DeviceMessage = message;
            }
            else if (authPrompt.AuthType == AuthType.Code)
            {
                IList <MfaCodeResponse> codeList = mfaArray?.ToObject <IList <MfaCodeResponse> >();
                authPrompt.CodeDeliveryOptions = codeList?.Select(c => c.ToCodeOption()).ToList();
            }
            else if (authPrompt.AuthType == AuthType.Questions)
            {
                IList <MfaQuestionResponse> questionList = mfaArray?.ToObject <IList <MfaQuestionResponse> >();
                authPrompt.Questions = questionList?.Select(c => c.Question).ToList();
            }
            else if (authPrompt.AuthType == AuthType.Selection)
            {
                IList <MfaSelectionResponse> selectionList = mfaArray?.ToObject <IList <MfaSelectionResponse> >();
                authPrompt.MultipleChoiceQuestions = selectionList?.Select(c => c.ToSelectionItem()).ToList();
            }

            return(authPrompt);
        }
Esempio n. 2
0
        public void AuthenticationPromptConstructorTest()
        {
            int    id                   = 0;            // TODO: Initialize to an appropriate value
            bool   isEchoed             = false;        // TODO: Initialize to an appropriate value
            string request              = string.Empty; // TODO: Initialize to an appropriate value
            AuthenticationPrompt target = new AuthenticationPrompt(id, isEchoed, request);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Esempio n. 3
0
 public void TestInitialize()
 {
     FilePersistedTestLab.SetDefaultFileLocations();
     this.settings = Settings.Instance;
     this.settings.PersistenceType = FilePersistence.TYPE_ID;
     this.passwordRequested        = false;
     this.exitCalled           = false;
     this.fallbackRequested    = false;
     this.authenticationPrompt = new AuthenticationPrompt();
     this.factory = new PersistenceFactory(Settings.Instance, TestConnectionManager.Instance, TestConnectionManager.CreateTestFavoriteIcons());
 }
Esempio n. 4
0
        /// <summary>
        /// Initialize new instance of the upgrade providing fresh not initialized persistence and password prompt.
        /// </summary>
        /// <param name="persistence">Not null,not authenticated, not initialized persistence</param>
        /// <param name="knowsUserPassword">Not null password prompt to obtain current master password from user</param>
        internal FilesV2ContentUpgrade(IPersistence persistence, ConnectionManager connectionManager, Func <bool, AuthenticationPrompt> knowsUserPassword)
        {
            this.persistence       = persistence;
            this.connectionManager = connectionManager;

            // prevents ask for password two times
            this.passwordsUpdate = new PasswordsV2Update(retry =>
            {
                this.prompt = knowsUserPassword(retry);
                return(this.prompt);
            });
        }
Esempio n. 5
0
        public void ResponseTest()
        {
            int    id                   = 0;                                               // TODO: Initialize to an appropriate value
            bool   isEchoed             = false;                                           // TODO: Initialize to an appropriate value
            string request              = string.Empty;                                    // TODO: Initialize to an appropriate value
            AuthenticationPrompt target = new AuthenticationPrompt(id, isEchoed, request); // TODO: Initialize to an appropriate value
            string expected             = string.Empty;                                    // TODO: Initialize to an appropriate value
            string actual;

            target.Response = expected;
            actual          = target.Response;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Esempio n. 6
0
        /// <summary>
        /// Private helper to handle responses from Add or Auth user API calls.
        /// </summary>
        private async Task <AddUserResult> ProcessAddOrAuthResponse(HttpResponseMessage response)
        {
            string responseJson = await response.Content?.ReadAsStringAsync();

            AddUserResult result = new AddUserResult();

            // 201 CREATED indicates success but requires multi-factor authentication
            if (response.StatusCode == HttpStatusCode.Created)
            {
                MfaResponse          mfaResponse = JsonConvert.DeserializeObject <MfaResponse>(responseJson);
                AuthenticationPrompt mfaPrompt   = mfaResponse?.ToAuthenticationPrompt();

                result.AccessToken = new AccessToken(mfaResponse?.AccessToken);
                result.AuthPrompt  = mfaPrompt;
                return(result);
            }

            // 200 OK indicates success, response includes access token and optionally accounts/transactions
            if (response.StatusCode == HttpStatusCode.OK)
            {
                AddUserResponse userResponse = JsonConvert.DeserializeObject <AddUserResponse>(responseJson);
                result.AccessToken = new AccessToken(userResponse.AccessToken);

                if (userResponse.Accounts != null)
                {
                    result.Accounts = userResponse.Accounts.Select(x => x.ToAccount()).ToList();
                }

                if (userResponse.Transactions != null)
                {
                    result.Transactions = userResponse.Transactions.Select(x => x.ToTransaction()).ToList();
                }

                return(result);
            }

            result.Exception = await this.ParseException(response, responseJson);

            return(result);
        }
Esempio n. 7
0
 internal DSMKeyboardInteractiveEventArgs(AuthenticationBannerEventArgs abe, AuthenticationPromptEventArgs ape, AuthenticationPrompt p)
 {
     if (abe != null) { Banner = abe.BannerMessage; } else { Banner = string.Empty; }
     Instruction = ape.Instruction;
     Language = ape.Language;
     Username = ape.Username;
     Request = p.Request;
     Id = p.Id;
     IsEchoed = p.IsEchoed;
 }