string ISasTokenProvider.GetSasToken()
        {
            lock (_lock)
            {
                if (TokenShouldBeGenerated())
                {
                    var builder = new SharedAccessSignatureBuilder
                    {
                        HostName           = Endpoint.Host,
                        SharedAccessPolicy = SharedAccessPolicy,
                        SharedAccessKey    = SharedAccessKey,
                        TimeToLive         = SasTokenTimeToLive,
                    };

                    _tokenExpiryTime = DateTimeOffset.UtcNow.Add(SasTokenTimeToLive);
                    _cachedSasToken  = builder.ToSignature();
                }

                return(_cachedSasToken);
            }
        }
        string ISasTokenProvider.GetSasToken()
        {
            lock (_lock)
            {
                if (IsTokenExpired())
                {
                    var builder = new SharedAccessSignatureBuilder
                    {
                        HostName           = _hostName,
                        SharedAccessPolicy = _sharedAccessPolicy,
                        SharedAccessKey    = _sharedAccessKey,
                        TimeToLive         = _timeToLive,
                    };

                    _tokenExpiryTime = DateTimeOffset.UtcNow.Add(_timeToLive);
                    _cachedSasToken  = builder.ToSignature();
                }

                return(_cachedSasToken);
            }
        }
        private AccessToken GetSasTokenAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            lock (_lock)
            {
                if (TokenShouldBeGenerated())
                {
                    var builder = new SharedAccessSignatureBuilder
                    {
                        HostName           = Endpoint.Host,
                        SharedAccessPolicy = SharedAccessPolicy,
                        SharedAccessKey    = SharedAccessKey,
                        TimeToLive         = SasTokenTimeToLive,
                    };

                    _tokenExpiryTime = DateTimeOffset.UtcNow.Add(SasTokenTimeToLive);
                    _cachedSasToken  = builder.ToSignature();
                }

                return(new AccessToken(_cachedSasToken, _tokenExpiryTime));
            }
        }