void SetToken(ManagedServiceTokenInfo info)
 {
     if (info != null)
     {
         _expiration  = DateTime.UtcNow + TimeSpan.FromSeconds(info.ExpiresIn);
         _accessToken = info.AccessToken;
     }
 }
Ejemplo n.º 2
0
 void GetOrRenewAuthentication()
 {
     if (_expiration - DateTime.UtcNow < ManagedServiceTokenInfo.TimeoutThreshold)
     {
         ManagedServiceTokenInfo info = null;
         while (info == null && RequestUris.Count > 0)
         {
             var currentRequestUri = RequestUris.Dequeue();
             try
             {
                 info = _tokenGetter.GetAsync(currentRequestUri, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult();
                 // if a request was succesful, we should not check any other Uris
                 RequestUris.Clear();
                 RequestUris.Enqueue(currentRequestUri);
             }
             catch (CloudException) when(RequestUris.Count > 0)
             {
                 // do nothing
             }
         }
         SetToken(info);
     }
 }