Пример #1
0
        public WebToken GetAccessToken()
        {
            if (_cachedToken == null || _cachedToken.Exprires < DateTime.UtcNow.AddMinutes(5))
            {
                if (_credential == null)
                {
                    _cachedToken = RequestWindowsToken();
                }
                else
                {
                    _cachedToken = RequestOAuthToken(_credential.UserName, _credential.Password);
                }
            }

            return _cachedToken;
        }
Пример #2
0
 private WebToken RequestToken(HttpWebRequest request)
 {
     HttpWebResponse response = _webClient.SendRequest(request);
     using (Stream stream = response.GetResponseStream())
     {
         using (var reader = new StreamReader(stream, Encoding.UTF8))
         {
             string content = reader.ReadToEnd();
             var accessToken = new WebToken(content);
             return accessToken;
         }
     }
 }