public async Task <AddUserResult> AddUser(CreateUserRequest request, CancellationToken token) { if (request.Password.Length < 6) { return(AddUserResult.Failed(AddUserResultError.PasswordNotStrong)); } var userCursor = await _users.FindAsync(u => u.Login == request.Login, cancellationToken : token); var user = await userCursor.FirstOrDefaultAsync(token); if (user != null) { return(AddUserResult.Failed(AddUserResultError.AlreadyExists)); } var newUser = new User { Login = request.Login, Password = request.Password }; await _users.InsertOneAsync(newUser, cancellationToken : token); return(AddUserResult.Success(newUser)); }
public static void AddUser(JObject request, ref JObject result, string language, ref Session session) { User user; try { user = JsonConvert.DeserializeObject<User>(request[AddUserFieldKeyword.User].ToString()); } catch (Exception) { AddBadParameterInfo(ref result, Functions.AddUser, language); return; } string message; if (UserHelper.Add(user, language, out message)) { var resultObject = new AddUserResult { User = user }; AddSuccessInfo(ref result, ResultType.Object, resultObject, message); } else { AddFailInfo(ref result, ErrorNumber.SeeDetail.ToString(), message); } }
public async Task <AddUserResultResponse> Add(int?id, [FromBody] AddUserRequest request) { AddUserCommand arg = new AddUserCommand(); this._mapper.Map(id, arg); this._mapper.Map(request, arg); AddUserResult result = await _addHandler.Execute(arg); return(_mapper.Map <AddUserResultResponse>(result)); }
public async Task AuthUserSelection() { IHttpClientWrapper httpClient = this.GetMockHttpClient("AuthUserCiti.json", HttpStatusCode.OK, HttpMethod.Post, "connect/step"); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AuthenticateUserAsync(new AccessToken("test_citi"), false, ApiType.Connect, "tomato", "ketchup"); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsFalse(result.IsMfaRequired); Assert.IsNull(result.AuthPrompt); }
public async Task AddUserWithPinSuccess() { IHttpClientWrapper httpClient = this.GetMockHttpClient("AddUserPinSuccess.json", HttpStatusCode.Created, HttpMethod.Post); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AddUserAsync(BaseTestClass.TestUsername, BaseTestClass.TestPassword, InstitutionType.Usaa, null, "1234"); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsTrue(result.IsMfaRequired); Assert.IsNotNull(result.AccessToken); }
public async Task UpdateUserWebhook() { IHttpClientWrapper httpClient = this.GetMockHttpClient("AddUserSuccess.json", HttpStatusCode.OK, new HttpMethod("PATCH")); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.UpdateUserAsync(new AccessToken("test_wells"), BaseTestClass.TestUsername, BaseTestClass.TestPassword, webhookUri : new Uri("http://dummy.test.com")); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsFalse(result.IsMfaRequired); Assert.IsNotNull(result.AccessToken); }
public async Task AuthUserSingleQuestion() { IHttpClientWrapper httpClient = this.GetMockHttpClient("AuthUserUsBank.json", HttpStatusCode.OK, HttpMethod.Post, "connect/step"); IPlaidClient testClient = this.GetPlaidClient(httpClient); AccessToken token = new AccessToken("test_us"); AddUserResult result = await testClient.AuthenticateUserAsync(token, false, ApiType.Connect, "tomato"); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsFalse(result.IsMfaRequired); Assert.IsNotNull(result.AccessToken); }
public async Task UpdateUserWithPin() { IHttpClientWrapper httpClient = this.GetMockHttpClient("QuestionMfa.json", HttpStatusCode.Created, new HttpMethod("PATCH")); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.UpdateUserAsync(new AccessToken("test_usaa"), BaseTestClass.TestUsername, BaseTestClass.TestPassword, "1234"); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsTrue(result.IsMfaRequired); Assert.IsNotNull(result.AuthPrompt); Assert.IsNotNull(result.AuthPrompt.Questions); }
public void TestAddADriver_secStation_usingStationController() { StationSignUpResponse res1 = new StationSignUpResponse { api_ret_code = 0, api_ret_message = "success", session_token = "token1", status = 200, timestamp = DateTime.UtcNow }; UserLogInResponse res2 = new UserLogInResponse { api_ret_message = "success", api_ret_code = 0, session_token = "token2", status = 200, timestamp = DateTime.UtcNow, groups = new List <UserGroup> { new UserGroup { creator_id = "creator1", description = "gdesc1", group_id = "group_id1", name = "group1" } }, user = new UserInfo { user_id = "uid1" }, stations = new List <UserStation>() { new UserStation() { station_id = "aabbcc" }, } }; StationLogOnResponse res3 = new StationLogOnResponse(200, DateTime.UtcNow, "token3"); res3.api_ret_code = 0; using (FakeCloud cloud = new FakeCloud(res1)) { cloud.addJsonResponse(res3); cloud.addJsonResponse(res2); StationController.StationMgmtURL = "http://127.0.0.1:8080/v2/"; AddUserResult result = StationController.AddUser("*****@*****.**", "123456"); Assert.AreEqual("uid1", result.UserId); Assert.IsFalse(result.IsPrimaryStation); } }
public async Task AddUserCodeAuth() { IHttpClientWrapper httpClient = this.GetMockHttpClient("DeviceCodeMfa.json", HttpStatusCode.Created, HttpMethod.Post); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AddUserAsync(BaseTestClass.TestUsername, BaseTestClass.TestPassword, InstitutionType.Chase); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsTrue(result.IsMfaRequired); Assert.AreEqual(AuthType.Device, result.AuthPrompt.AuthType); Assert.IsNull(result.AuthPrompt.CodeDeliveryOptions); Assert.IsFalse(string.IsNullOrWhiteSpace(result.AuthPrompt.DeviceMessage)); }
public async Task AddUserQuestionAuth() { IHttpClientWrapper httpClient = this.GetMockHttpClient("QuestionMfa.json", HttpStatusCode.Created, HttpMethod.Post); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AddUserAsync(BaseTestClass.TestUsername, BaseTestClass.TestPassword, InstitutionType.UsBank); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsTrue(result.IsMfaRequired); Assert.AreEqual(AuthType.Questions, result.AuthPrompt.AuthType); Assert.IsNotNull(result.AuthPrompt.Questions); Assert.AreEqual(1, result.AuthPrompt.Questions.Count); }
public async Task AddUserLocked() { IHttpClientWrapper httpClient = this.GetMockHttpClient("AccountLocked.json", HttpStatusCode.PaymentRequired, HttpMethod.Post); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AddUserAsync(BaseTestClass.TestUsername, "plaid_locked", BaseTestClass.TestInstitution); Assert.IsNotNull(result); Assert.IsTrue(result.IsError); Assert.IsNotNull(result.Exception); Assert.AreEqual(402, result.Exception.HttpStatusCode); Assert.AreEqual(ErrorCode.AccountLocked, result.Exception.ErrorCode); Assert.IsFalse(string.IsNullOrWhiteSpace(result.Exception.Message)); Assert.IsFalse(string.IsNullOrWhiteSpace(result.Exception.Resolution)); }
public async Task AddUserInvalidCreds() { IHttpClientWrapper httpClient = this.GetMockHttpClient("InvalidCredentials.json", HttpStatusCode.PaymentRequired, HttpMethod.Post); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AddUserAsync("test_bad", BaseTestClass.TestPassword, BaseTestClass.TestInstitution); Assert.IsNotNull(result); Assert.IsTrue(result.IsError); Assert.IsNotNull(result.Exception); Assert.AreEqual(402, result.Exception.HttpStatusCode); Assert.AreEqual(ErrorCode.InvalidCredentials, result.Exception.ErrorCode); Assert.IsFalse(string.IsNullOrWhiteSpace(result.Exception.Message)); Assert.IsFalse(string.IsNullOrWhiteSpace(result.Exception.Resolution)); }
public async Task AuthUserCodeDeviceType() { IHttpClientWrapper httpClient = this.GetMockHttpClient("DeviceCodeMfa.json", HttpStatusCode.Created, HttpMethod.Post, "connect/step"); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AuthenticateUserAsync(new AccessToken("test_chase"), DeliveryType.Phone); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsTrue(result.IsMfaRequired); Assert.AreEqual(AuthType.Device, result.AuthPrompt.AuthType); Assert.IsNull(result.AuthPrompt.CodeDeliveryOptions); Assert.IsFalse(string.IsNullOrWhiteSpace(result.AuthPrompt.DeviceMessage)); }
public async Task AddUserLoginOnlySuccess() { IHttpClientWrapper httpClient = this.GetMockHttpClient("AddUserSuccess.json", HttpStatusCode.OK, HttpMethod.Post); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AddUserAsync(BaseTestClass.TestUsername, BaseTestClass.TestPassword, BaseTestClass.TestInstitution); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsFalse(result.IsMfaRequired); Assert.IsNotNull(result.AccessToken); // For some reason their test account returns this data no matter what // Assert.IsNull(result.Accounts); // Assert.IsNull(result.Transactions); }
public async Task AddUserInvalidPin() { IHttpClientWrapper httpClient = this.GetMockHttpClient("InvalidPin.json", HttpStatusCode.PaymentRequired, HttpMethod.Post); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AddUserAsync(BaseTestClass.TestUsername, BaseTestClass.TestPassword, InstitutionType.Usaa, null, "4567"); Assert.IsNotNull(result); Assert.IsTrue(result.IsError); Assert.IsFalse(result.IsMfaRequired); Assert.AreEqual(402, result.Exception.HttpStatusCode); Assert.AreEqual(ErrorCode.InvalidPin, result.Exception.ErrorCode); Assert.IsFalse(string.IsNullOrWhiteSpace(result.Exception.Message)); Assert.IsFalse(string.IsNullOrWhiteSpace(result.Exception.Resolution)); }
public async Task AddUserNoPin() { IHttpClientWrapper httpClient = this.GetMockHttpClient("MissingCredentials.json", HttpStatusCode.BadRequest, HttpMethod.Post); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AddUserAsync(BaseTestClass.TestUsername, BaseTestClass.TestPassword, InstitutionType.Usaa); Assert.IsNotNull(result); Assert.IsTrue(result.IsError); Assert.IsFalse(result.IsMfaRequired); Assert.AreEqual(400, result.Exception.HttpStatusCode); Assert.AreEqual(ErrorCode.CredentialsMissing, result.Exception.ErrorCode); Assert.IsFalse(string.IsNullOrWhiteSpace(result.Exception.Message)); Assert.IsFalse(string.IsNullOrWhiteSpace(result.Exception.Resolution)); }
public async Task AuthUserInvalidAnswer() { IHttpClientWrapper httpClient = this.GetMockHttpClient("InvalidMfa.json", HttpStatusCode.PaymentRequired, HttpMethod.Post, "connect/step"); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AuthenticateUserAsync(new AccessToken("test_citi"), false, ApiType.Connect, "tomato"); Assert.IsNotNull(result); Assert.IsTrue(result.IsError); Assert.IsFalse(result.IsMfaRequired); Assert.IsNotNull(result.Exception); Assert.AreEqual(ErrorCode.InvalidMfa, result.Exception.ErrorCode); Assert.IsFalse(string.IsNullOrWhiteSpace(result.Exception.Message)); Assert.IsFalse(string.IsNullOrWhiteSpace(result.Exception.Resolution)); }
public async Task AddUserSelectionAuth() { IHttpClientWrapper httpClient = this.GetMockHttpClient("SelectionMfa.json", HttpStatusCode.Created, HttpMethod.Post); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserResult result = await testClient.AddUserAsync("plaid_selections", BaseTestClass.TestPassword, InstitutionType.Citi); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsTrue(result.IsMfaRequired); Assert.AreEqual(AuthType.Selection, result.AuthPrompt.AuthType); Assert.IsNotNull(result.AuthPrompt.MultipleChoiceQuestions); Assert.AreEqual(2, result.AuthPrompt.MultipleChoiceQuestions.Count); Assert.IsFalse(string.IsNullOrWhiteSpace(result.AuthPrompt.MultipleChoiceQuestions[0].Question)); Assert.AreEqual(2, result.AuthPrompt.MultipleChoiceQuestions[0].Options.Count); Assert.IsFalse(string.IsNullOrWhiteSpace(result.AuthPrompt.MultipleChoiceQuestions[1].Question)); Assert.AreEqual(2, result.AuthPrompt.MultipleChoiceQuestions[1].Options.Count); }
/// <inheritdoc /> public async Task <PlaidResult <IList <Account> > > GetAccountsAsync(AccessToken accessToken) { Condition.Requires(accessToken).IsNotNull(); PlaidRequest balanceRequest = new PlaidRequest(this.clientId, this.clientSecret, accessToken.Value); HttpResponseMessage response = await this.httpClient.PostAsJsonAsync("balance", balanceRequest); // Re-use add user result since it contains the account objects of interest AddUserResult userResult = await this.ProcessAddOrAuthResponse(response); PlaidResult <IList <Account> > result = new PlaidResult <IList <Account> >(); if (userResult.Accounts != null) { result.Value = new List <Account>(userResult.Accounts); } result.Exception = userResult.Exception; return(result); }
/// <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); }
public async Task AddUserListCodeAuth() { IHttpClientWrapper httpClient = this.GetMockHttpClient("DeviceListMfa.json", HttpStatusCode.Created, HttpMethod.Post); IPlaidClient testClient = this.GetPlaidClient(httpClient); AddUserOptions options = new AddUserOptions { IncludeMfaList = true }; AddUserResult result = await testClient.AddUserAsync(BaseTestClass.TestUsername, BaseTestClass.TestPassword, InstitutionType.Chase, options); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsTrue(result.IsMfaRequired); Assert.AreEqual(AuthType.Code, result.AuthPrompt.AuthType); Assert.IsNotNull(result.AuthPrompt.CodeDeliveryOptions); Assert.AreEqual(2, result.AuthPrompt.CodeDeliveryOptions.Count); Assert.IsFalse(string.IsNullOrWhiteSpace(result.AuthPrompt.CodeDeliveryOptions[0].Mask)); Assert.AreEqual(DeliveryType.Phone, result.AuthPrompt.CodeDeliveryOptions[0].Type); Assert.IsFalse(string.IsNullOrWhiteSpace(result.AuthPrompt.CodeDeliveryOptions[1].Mask)); Assert.AreEqual(DeliveryType.Email, result.AuthPrompt.CodeDeliveryOptions[1].Type); }
public async Task AuthUserMultipleQuestions() { IHttpClientWrapper httpClient = this.GetMockHttpClient("QuestionMfa.json", HttpStatusCode.Created, HttpMethod.Post, "connect/step"); IPlaidClient testClient = this.GetPlaidClient(httpClient); testClient = this.GetPlaidClient(httpClient); AccessToken token = new AccessToken("test_us"); AddUserResult result = await testClient.AuthenticateUserAsync(token, false, ApiType.Connect, "again"); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsTrue(result.IsMfaRequired); Assert.IsNotNull(result.AuthPrompt); Assert.IsNotNull(result.AuthPrompt.Questions); Assert.IsNotNull(result.AccessToken); httpClient = this.GetMockHttpClient("AuthUserUsBank.json", HttpStatusCode.OK, HttpMethod.Post, "connect/step"); testClient = this.GetPlaidClient(httpClient); result = await testClient.AuthenticateUserAsync(token, false, mfaValues : "tomato"); Assert.IsNotNull(result); Assert.IsFalse(result.IsError); Assert.IsFalse(result.IsMfaRequired); Assert.IsNotNull(result.AccessToken); }
public void TestAddADriver_usingStationController() { StationSignUpResponse res1 = new StationSignUpResponse { api_ret_code = 0, api_ret_message = "success", session_token = "token1", status = 200, timestamp = DateTime.UtcNow }; UserLogInResponse res2 = new UserLogInResponse { api_ret_message = "success", api_ret_code = 0, session_token = "token2", status = 200, timestamp = DateTime.UtcNow, groups = new List <UserGroup> { new UserGroup { creator_id = "creator1", description = "gdesc1", group_id = "group_id1", name = "group1" } }, user = new UserInfo { user_id = "uid1" }, stations = new List <UserStation>() { new UserStation() { station_id = "stationId", type = "primary" } } }; StationLogOnResponse res3 = new StationLogOnResponse(200, DateTime.UtcNow, "token3"); res3.api_ret_code = 0; using (FakeCloud cloud = new FakeCloud(res1)) { cloud.addJsonResponse(res3); cloud.addJsonResponse(res2); StationController.StationMgmtURL = "http://127.0.0.1:8080/v2/"; AddUserResult result = StationController.AddUser("*****@*****.**", "123456"); Assert.AreEqual("uid1", result.UserId); Assert.IsTrue(result.IsPrimaryStation); // verify db Driver driver = mongodb.GetDatabase("wammer"). GetCollection <Driver>("drivers").FindOne( Query.EQ("email", "*****@*****.**")); Assert.AreEqual("*****@*****.**", driver.email); Assert.AreEqual(@"resource\user_uid1", driver.folder); Assert.AreEqual(res2.user.user_id, driver.user_id); Assert.IsTrue(driver.isPrimaryStation); Assert.AreEqual(1, driver.groups.Count); Assert.AreEqual(res2.session_token, driver.session_token); Assert.AreEqual(res2.groups[0].group_id, driver.groups[0].group_id); Assert.AreEqual(res2.groups[0].name, driver.groups[0].name); Assert.AreEqual(res2.groups[0].description, driver.groups[0].description); //verify station Wammer.Model.StationInfo s = Wammer.Model.StationCollection.Instance.FindOne(); Assert.IsNotNull(s); Assert.AreEqual("token3", s.SessionToken); } }
private void btnSignIn_Click(object sender, EventArgs e) { if ((cmbEmail.Text == string.Empty) || (txtPassword.Text == string.Empty)) { MessageBox.Show(I18n.L.T("FillAllFields"), "Waveface", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!TestEmailFormat(cmbEmail.Text)) { MessageBox.Show(I18n.L.T("InvalidEmail"), "Waveface", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { Cursor = Cursors.WaitCursor; UserLoginSetting userlogin = userloginContainer.GetUserLogin(cmbEmail.Text); if (userlogin == null) { AddUserResult res = StationController.AddUser(cmbEmail.Text.ToLower(), txtPassword.Text); userlogin = new UserLoginSetting { Email = cmbEmail.Text.ToLower(), Password = SecurityHelper.EncryptPassword(txtPassword.Text), RememberPassword = chkRememberPassword.Checked }; userloginContainer.UpsertUserLoginSetting(userlogin); RefreshUserList(); if (res.IsPrimaryStation) { GotoTabPage(tabMainStationSetup, userlogin); } else { LaunchWavefaceClient(userlogin); Close(); } } else { StationController.StationOnline(userlogin.Email, txtPassword.Text); userlogin.Password = SecurityHelper.EncryptPassword(txtPassword.Text); userlogin.RememberPassword = chkRememberPassword.Checked; userloginContainer.UpsertUserLoginSetting(userlogin); RefreshUserList(); LaunchWavefaceClient(userlogin); Close(); } } catch (AuthenticationException) { MessageBox.Show(I18n.L.T("AuthError"), "Waveface", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtPassword.Text = string.Empty; txtPassword.Focus(); } catch (StationServiceDownException) { MessageBox.Show(I18n.L.T("StationDown"), "Waveface", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (Exception) { MessageBox.Show(I18n.L.T("UnknownSigninError"), "Waveface", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { Cursor = Cursors.Default; } }