Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public override bool CallAPI()
  2. {
  3. try
  4. {
  5. bool isSPAdded = false;
  6. int counter = 0;
  7. do
  8. {
  9. Uri uri = new Uri(_settings.HostUrl + "/auth/realms/master/protocol/openid-connect/token");
  10. var requestContent = string.Format("username={0}&password={1}&client_id=admin-cli&grant_type=password", _settings.UserName, _settings.Password);
  11. StringContent _requestContent = new StringContent(requestContent, Encoding.UTF8, "application/x-www-form-urlencoded");
  12. _response = _client.PostAsync(uri, _requestContent).Result;
  13.  
  14. if (_response.IsSuccessStatusCode)
  15. {
  16.  
  17. Uri uri = new Uri(String.Format(_settings.HostUrl + "/auth/admin/realms/{0}/clients", Node.OrgId));
  18. _requestContent = new StringContent(response.Content.ReadAsStringAsync().Result, Encoding.UTF8, "application/json");
  19.  
  20. _response = _client.PostAsync(uri, _requestContent).Result;
  21. if (_response.IsSuccessStatusCode)
  22. {
  23. isSPAdded = _response.IsSuccessStatusCode;
  24. break;
  25. }
  26. }
  27. counter++;
  28. } while (_response.StatusCode == HttpStatusCode.Unauthorized && _response.Content.ReadAsStringAsync().Result == "Bearer" && counter < 2);
  29.  
  30. return isSPAdded;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement