Example #1
0
        protected string mfaWithOkta(string username)
        {
            OktaSettings oktaSettings = new Okta.Core.OktaSettings();

            oktaSettings.ApiToken = "00jSoRPyhdLF9MBypNmvkdm0LEXKZAc4tam7lw1Dqq";
            oktaSettings.BaseUri  = new Uri("https://org.oktapreview.com");

            UsersClient usersClient = new UsersClient(oktaSettings);

            //create with fakedomain, fake email, fake first&last name
            User tempUser = new User(username + "@oktalife.info", "*****@*****.**", "Fake", "Fake");


            tempUser.Credentials = new LoginCredentials();

            String password = System.Convert.ToBase64String(HMACSHA256PasswordGenerator.GenerateHash(username));

            tempUser.Credentials.Password.Value = password;

            string[] groups = new string[1];

            //add the user to the Okta group that prompts for MFA
            groups[0] = "00gbdoy4imvfNeV3Z0h7";
            tempUser.SetProperty("groupIds", groups);
            Console.WriteLine(tempUser.ToJson());

            try
            {
                usersClient.Add(tempUser, true);
            }
            catch (OktaException ex)
            {
                //user already created, move on
            }

            AuthClient   authN    = new Okta.Core.Clients.AuthClient(oktaSettings);
            AuthResponse authResp = authN.Authenticate(username, password);

            return(authResp.StateToken);
        }
        private void Setup(string apiToken, Uri baseUri)
        {
            settings = new OktaSettings();
            settings.ApiToken = apiToken;
            settings.BaseUri = baseUri;

            client = new OktaClient(settings);
            users = client.GetUsersClient();
            groups = client.GetGroupsClient();
            sessions = client.GetSessionsClient();
            apps = client.GetAppsClient();
            authn = new AuthClient(settings);
            factors = new OrgFactorsClient(settings);
        }