private void CheckAndRefreshTokenProvider()
        {
            if (!Object.ReferenceEquals(this.currentKeyObject, this.azureKeyCredential.Key))
            {
                // Change is immediate for all new reqeust flows (pure compute work and should be very very quick)
                // With-out lock possibility of concurrent updates (== #inflight reqeust's) but eventually only one will win
                lock (this.refreshLock)
                {
                    // Process only if the authProvider is not yet exchanged
                    if (!Object.ReferenceEquals(this.currentKeyObject, this.azureKeyCredential.Key))
                    {
                        AuthorizationTokenProvider newAuthProvider     = AuthorizationTokenProvider.CreateWithResourceTokenOrAuthKey(this.azureKeyCredential.Key);
                        AuthorizationTokenProvider currentAuthProvider = Interlocked.Exchange(ref this.authorizationTokenProvider, newAuthProvider);

                        if (!Object.ReferenceEquals(newAuthProvider, currentAuthProvider))
                        {
                            // NewAuthProvider =>
                            // 1. Credentials changed
                            // 2. Dispose current token provider: NOT Disposed actively: There might be inflight usage => leaving it to GC finalizers
                            Interlocked.Exchange(ref this.currentKeyObject, this.azureKeyCredential.Key);
                        }
                    }
                }
            }
        }
 public void Init()
 {
     _zonkyApi      = ZonkyApiFactory.Create();
     _tokenProvider = new AuthorizationTokenProvider(_zonkyApi);
 }
Example #3
0
 public void Init()
 {
     _zonkyApi      = new ZonkyApi(new HttpClient());
     _tokenProvider = new AuthorizationTokenProvider(_zonkyApi);
 }
 public override void Dispose()
 {
     this.authorizationTokenProvider?.Dispose();
     this.authorizationTokenProvider = null;
 }