private async Task <string> getAuthToken(string clientId, string clientSecret, string tokenUrl) { if (_tokenDict.TryGetValue(clientId, out var token)) { if (token.IsValid()) { return(token.GetAccessToken()); } else { this.removeAuthToken(clientId); } } using (var client = _clientFactory.CreateClient()) { var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest { Address = tokenUrl, ClientId = clientId, ClientSecret = clientSecret }); if (response.IsError) { return(null); } var cachedToken = new CachedToken(response); _tokenDict.TryAdd(clientId, cachedToken); return(cachedToken.GetAccessToken()); } }