private async Task CheckUpdateTokenAsync() { var token = await authToken.GetAccessTokenAsync().ConfigureAwait(false); if (token != authorizationHeaderValue) { // Updates the access token. authorizationHeaderValue = token; var headers = client.DefaultRequestHeaders; if (headers.Contains(AuthorizationHeader)) { headers.Remove(AuthorizationHeader); } headers.Add(AuthorizationHeader, authorizationHeaderValue); } }
private async Task CheckUpdateTokenAsync() { if (string.IsNullOrWhiteSpace(SubscriptionKey)) { throw new ArgumentException("Invalid Subscription Key. Go to Azure Portal and sign up for Microsoft Translator: https://portal.azure.com/#create/Microsoft.CognitiveServices/apitype/TextTranslation"); } var token = await authToken.GetAccessTokenAsync().ConfigureAwait(false); if (token != authorizationHeaderValue) { // Updates the access token. authorizationHeaderValue = token; var headers = client.DefaultRequestHeaders; if (headers.Contains(AUTHORIZATION_HEADER)) { headers.Remove(AUTHORIZATION_HEADER); } headers.Add(AUTHORIZATION_HEADER, authorizationHeaderValue); } }