public OktaHttpClient(OktaSettings oktaSettings) { if (oktaSettings.BaseUri == null || oktaSettings.ApiToken == null) { throw new OktaException("Both a BaseUri and an ApiToken must be provided"); } if (oktaSettings.CustomHttpHandler != null) { if (oktaSettings.DisposeCustomHttpHandler != null) { httpClient = new HttpClient(oktaSettings.CustomHttpHandler, oktaSettings.DisposeCustomHttpHandler.Value); } else { httpClient = new HttpClient(oktaSettings.CustomHttpHandler); } httpClient.Timeout = Constants.DefaultTimeout; } this.BaseUri = oktaSettings.BaseUri; this.ApiToken = oktaSettings.ApiToken; httpClient.DefaultRequestHeaders.Add("Accept", "application/json"); httpClient.DefaultRequestHeaders.Add("User-agent", Constants.UserAgent); }
protected void Button2_Click1(object sender, EventArgs e) { OktaSettings oktaSettings = new Okta.Core.OktaSettings(); oktaSettings.ApiToken = "00jSoRPyhdLF9MBypNmvkdm0LEXKZAc4tam7lw1Dqq"; oktaSettings.BaseUri = new Uri("https://org.oktapreview.com"); SessionsClient sessionsClient = new SessionsClient(oktaSettings); try { sessionsClient.CreateSession(sessionToken.Text); ResultOfMFA.Text = "Successful MFA with Okta"; } catch (OktaException) { //Invalid session validation, don't let them through ResultOfMFA.Text = "Invalid MFA with Okta"; } ResultOfMFA.Style.Add("display", "block"); }
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); }