public static string GetOAuthAccessTokenCore(IEnumerator <Uri> stsUris, Func <Uri, Uri> uriBuilder, string requestToken, TimeSpan timeout, out DateTime expiresIn, out string audience) { byte[] bytes = Encoding.UTF8.GetBytes(requestToken); string end = null; expiresIn = DateTime.MinValue; audience = null; bool flag = stsUris.MoveNext(); while (flag) { Uri uri = uriBuilder(stsUris.Current); try { HttpWebRequest servicePointMaxIdleTimeMilliSeconds = WebRequest.Create(uri) as HttpWebRequest; servicePointMaxIdleTimeMilliSeconds.ServicePoint.MaxIdleTime = Constants.ServicePointMaxIdleTimeMilliSeconds; servicePointMaxIdleTimeMilliSeconds.AllowAutoRedirect = true; servicePointMaxIdleTimeMilliSeconds.MaximumAutomaticRedirections = 1; servicePointMaxIdleTimeMilliSeconds.Method = "POST"; servicePointMaxIdleTimeMilliSeconds.ContentType = "application/x-www-form-urlencoded"; servicePointMaxIdleTimeMilliSeconds.ContentLength = (long)((int)bytes.Length); servicePointMaxIdleTimeMilliSeconds.Timeout = TokenProviderHelper.ConvertToInt32(timeout); using (Stream requestStream = servicePointMaxIdleTimeMilliSeconds.GetRequestStream()) { requestStream.Write(bytes, 0, (int)bytes.Length); } using (HttpWebResponse response = servicePointMaxIdleTimeMilliSeconds.GetResponse() as HttpWebResponse) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8)) { end = streamReader.ReadToEnd(); TokenProviderHelper.ExtractExpiresInAndAudience(end, out expiresIn, out audience); } } } flag = false; } catch (ArgumentException argumentException) { TokenProviderHelper.ThrowException(uri, argumentException); } catch (WebException webException1) { WebException webException = webException1; flag = stsUris.MoveNext(); if (!flag) { TokenProviderHelper.ThrowException(uri, webException); } } } return(end); }