Example #1
0
        public void AuthEnrollQuestionFactor()
        {
            string strEx     = string.Empty;
            string strStatus = string.Empty;

            TestUser dbUser = Helpers.GetUser(TestContext);

            if (dbUser.Activate)
            {
                try
                {
                    var          authClient   = oktaClient.GetAuthClient();
                    AuthResponse authResponse = authClient.Authenticate(dbUser.Login, dbUser.Password);

                    if (authResponse.Status == Models.AuthStatus.MfaEnroll && authResponse.StateToken != null) //there is an MFA policy that requires the user to enroll
                    {
                        var           usersClient      = oktaClient.GetUsersClient();
                        User          user             = usersClient.GetByUsername(dbUser.Login);
                        var           userFactorClient = oktaClient.GetUserFactorsClient(user);
                        List <Factor> userFactors      = userFactorClient.GetFactorCatalog();
                        Factor        questionFactor   = new Factor();
                        //foreach (Factor factor in userFactors)
                        //{
                        //    if(factor.FactorType == Models.FactorType.Question)
                        //    {
                        //        questionFactor = factor;
                        //        break;
                        //    }
                        //}
                        if (questionFactor != null)
                        {
                            List <Question> questions = userFactorClient.GetQuestions();
                            if (questions != null && questions.Count > 0)
                            {
                                questionFactor.Provider             = Models.FactorProviderType.Okta;
                                questionFactor.FactorType           = Models.FactorType.Question;
                                questionFactor.Profile.QuestionType = questions[0].QuestionType;
                                questionFactor.Profile.Answer       = "This is a test answer";
                                authResponse = authClient.Enroll(authResponse.StateToken, questionFactor);
                                strStatus    = authResponse.Status;
                            }
                        }
                    }
                }
                catch (OktaException e)
                {
                    strEx = string.Format("Error Code: {0} - Summary: {1} - Message: {2}", e.ErrorCode, e.ErrorSummary, e.Message);
                }
                catch (Exception ex)
                {
                    strEx = ex.ToString();
                }
            }
        }
        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);
                }
            }
        }