Example #1
0
        public Profile GetOktaUsers()
        {
            const string url = "replace with actual value";

            OktaAttributes[] oAttributes = new OktaAttributes[2];
            Attributes       attributes2 = new Attributes();
            List <Profile>   attributes  = new List <Profile>();
            Profile          prfle       = new Profile();

            using (var client = new HttpClient())
            {
                var apitoken = "replace with actual value";
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("SSWS", apitoken);
                HttpResponseMessage response = client.GetAsync(url).Result;
                var     data      = response.Content.ReadAsStringAsync().Result;
                dynamic oktaUserD = JArray.Parse(data);
                JArray  oktaUser  = JArray.Parse(data);
                for (int i = 0; i < oktaUser.Count; i++)
                {
                    attributes2.id  = oktaUser[i]["id"].ToString();
                    prfle.firstName = oktaUser[i]["profile"]["firstName"].ToString();
                    prfle.lastName  = oktaUser[i]["profile"]["lastName"].ToString();
                    prfle.email     = oktaUser[i]["profile"]["email"].ToString();
                    prfle.login     = oktaUser[i]["profile"]["login"].ToString();
                    attributes.Add(prfle);
                }
            }
            return(prfle);
        }
Example #2
0
        public Profile GetOktaUser(long userId)
        {
            const string url = "Replace with actual value";

            OktaAttributes[] oAttributes = new OktaAttributes[2];
            Attributes       attributes2 = new Attributes();
            List <Profile>   attributes  = new List <Profile>();
            Profile          prfle       = new Profile();

            if (userId > 0)
            {
                using (var client = new HttpClient())
                {
                    var apitoken = "Replace with actual value";
                    client.BaseAddress = new Uri(url);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("SSWS", apitoken);
                    HttpResponseMessage response = client.GetAsync(url).Result;
                    var    data     = response.Content.ReadAsStringAsync().Result;
                    JArray oktaUser = JArray.Parse(data);

                    foreach (JObject item in oktaUser)
                    {
                        attributes2.id  = item["id"].ToString();
                        prfle.firstName = item["profile"]["firstName"].ToString();
                        prfle.lastName  = item["profile"]["lastName"].ToString();
                        prfle.email     = item["profile"]["email"].ToString();
                        prfle.login     = item["profile"]["login"].ToString();
                        attributes.Add(prfle);
                    }
                }
            }
            else
            {
                Console.WriteLine("The user already exit");
            }
            return(prfle);
        }