/// <inheritdoc/>
        public async Task SetAsync(string clientName, string accessToken, int expiresIn, string refreshToken)
        {
            if (clientName is null)
            {
                throw new ArgumentNullException(nameof(clientName));
            }

            var expiration      = DateTimeOffset.UtcNow.AddSeconds(expiresIn);
            var expirationEpoch = expiration.ToUnixTimeSeconds();

            PasswordAccessToken passwordAccessToken = new PasswordAccessToken
            {
                AccessToken  = accessToken,
                RefreshToken = refreshToken,
                Expiration   = DateTimeOffset.FromUnixTimeSeconds(expirationEpoch)
            };

            //var entryOptions = new DistributedCacheEntryOptions
            //{
            //  AbsoluteExpiration = cacheExpiration
            //};

            _logger.LogDebug("Caching access token for client: {clientName}", clientName);
            await _cache.SetStringAsync(_options.Password.CacheKeyPrefix + clientName, JsonSerializer.Serialize(passwordAccessToken));
        }
        /// <inheritdoc/>
        public async Task <string> GetPasswordAccessTokenAsync(string clientName = AccessTokenManagementDefaults.DefaultTokenClientName, bool forceRenewal = false)
        {
            try
            {
                return(await PasswordTokenRequestDictionary.GetOrAdd(clientName, _ =>
                {
                    return new Lazy <Task <string> >(async() =>
                    {
                        PasswordAccessToken passwordAccessToken = await _passwordAccessTokenCache.GetAsync(clientName);;
                        if (passwordAccessToken == null)
                        {
                            _logger.LogDebug("No token data found in password token cache");
                            var response = await _tokenEndpointService.RequestPasswordTokenAsync("", "", clientName);
                            if (response.IsError)
                            {
                                _logger.LogError("Error requesting password access token for client {clientName}. Error = {error}", clientName, response.Error);
                                return null;
                            }
                            await _passwordAccessTokenCache.SetAsync(clientName, response.AccessToken, response.ExpiresIn, response.RefreshToken);
                            return response.AccessToken;
                        }

                        var dtRefresh = passwordAccessToken.Expiration.Subtract(_options.User.RefreshBeforeExpiration);
                        if (dtRefresh < _clock.UtcNow || forceRenewal == true)
                        {
                            _logger.LogDebug("Token for password needs refreshing.");
                            var refreshed = await _tokenEndpointService.RefreshUserAccessTokenAsync(passwordAccessToken.RefreshToken);
                            await _passwordAccessTokenCache.SetAsync(clientName, refreshed.AccessToken, refreshed.ExpiresIn, refreshed.RefreshToken);
                            return refreshed.AccessToken;
                        }

                        return passwordAccessToken.AccessToken;
                    });
                }).Value);
            }
            finally
            {
                PasswordTokenRequestDictionary.TryRemove(clientName, out _);
            }
        }