private void NonPostBackEvents() { this.btnDone.Visible = false; string userId = this.Master.Profile.Id; User user = Factory.UserClient.Get(userId); if (!string.IsNullOrEmpty(user.Profile.MobilePhone)) { // add SMS as a factor, if there's a phone number UserFactorsClient factorsClient = Factory.UserClient.GetUserFactorsClient(user); Factor to_enroll = new Factor { FactorType = FactorType.Sms, Provider = "OKTA", Profile = { PhoneNumber = user.Profile.MobilePhone } }; Factor factor = factorsClient.Enroll(to_enroll); this.tbFactorID.Value = factor.Id; } }
public void AssignFactorToUser() { TestUser dbUser = Helpers.GetUser(TestContext); string strEx = string.Empty; if (dbUser.Factors != null && dbUser.Factors.Count > 0) { Models.User existingUser = null; string strUserLogin = dbUser.Login; try { var usersClient = oktaClient.GetUsersClient(); existingUser = usersClient.Get(strUserLogin); Assert.IsNotNull(existingUser, "Okta user {0} does not exist", dbUser.Login); if (existingUser != null) { UserFactorsClient factorsClient = oktaClient.GetUserFactorsClient(existingUser); foreach (string strFactor in dbUser.Factors) { Models.Factor orgFactor = orgFactorsClient.GetFactor(strFactor); if (orgFactor != null && orgFactor.Status == "ACTIVE") { Models.Factor userFactor = factorsClient.Enroll(orgFactor); Assert.IsTrue(userFactor.Status == "ACTIVE", string.Format("Factor {0} status for user {1} is {2}", orgFactor.Id, dbUser.Login, userFactor.Status)); } } } } catch (OktaException e) { strEx = string.Format("Error Code: {0} - Summary: {1} - Message: {2}", e.ErrorCode, e.ErrorSummary, e.Message); } } }