private async Task <DiffResponse> CallAdAsync(Uri requestUri) { if (string.IsNullOrEmpty(_accessToken)) { _infoLogger("CallAdAsync", "Missing token - trying to retrieve..."); _accessToken = await _tokenRetriever().ConfigureAwait(false); } _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken); var result = await ExecuteHttpRequestAsync(requestUri).ConfigureAwait(false); if (result.StatusCode == HttpStatusCode.Unauthorized) { _infoLogger("CallAdAsync", "Unauthorized, trying to get new token"); _accessToken = await _tokenRetriever().ConfigureAwait(false); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken); result = await ExecuteHttpRequestAsync(requestUri).ConfigureAwait(false); if (!result.IsSuccessStatusCode) { return(null); } } var data = await DiffHelpers.ParseResponseAsync(result, _infoLogger).ConfigureAwait(false); return(data); }
public async Task <GraphResponse> GetObjectsAsync(string deltaLink = "") { try { var request = new DiffRequest { DeltaLink = deltaLink }; var queryParams = DiffHelpers.GenerateQueryParams(request); var requestUri = new Uri($"https://graph.windows.net/{_tenantId}/directoryObjects").AddQueryParameters( queryParams); var data = await CallAdAsync(requestUri).ConfigureAwait(false); return(data == null ? GraphResponse.CreateFailedResponse("Something went wrong") : GraphResponse.Create(data)); } catch (Exception ex) { _errorLogger("Something went wrong", ex.ToString()); return(GraphResponse.CreateFailedResponse(ex.ToString())); } }