Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override bool CallAPI()
- {
- try
- {
- bool isSPAdded = false;
- int counter = 0;
- do
- {
- Uri uri = new Uri(_settings.HostUrl + "/auth/realms/master/protocol/openid-connect/token");
- var requestContent = string.Format("username={0}&password={1}&client_id=admin-cli&grant_type=password", _settings.UserName, _settings.Password);
- StringContent _requestContent = new StringContent(requestContent, Encoding.UTF8, "application/x-www-form-urlencoded");
- _response = _client.PostAsync(uri, _requestContent).Result;
- if (_response.IsSuccessStatusCode)
- {
- Uri uri = new Uri(String.Format(_settings.HostUrl + "/auth/admin/realms/{0}/clients", Node.OrgId));
- _requestContent = new StringContent(response.Content.ReadAsStringAsync().Result, Encoding.UTF8, "application/json");
- _response = _client.PostAsync(uri, _requestContent).Result;
- if (_response.IsSuccessStatusCode)
- {
- isSPAdded = _response.IsSuccessStatusCode;
- break;
- }
- }
- counter++;
- } while (_response.StatusCode == HttpStatusCode.Unauthorized && _response.Content.ReadAsStringAsync().Result == "Bearer" && counter < 2);
- return isSPAdded;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement