Exemple #1
0
        public async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var token = await _tokenSource.GetTokenAsync();

            request.Headers.Authorization = new AuthenticationHeaderValue(BearerHeader, token);
            return(await _next.SendAsync(request));
        }
        private async Task <HttpRequestMessage> BuildBaseRequest(HttpMethod method, string url, string supportedMedia = LrpMediaTypeV2)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }
            if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
            {
                throw new ArgumentException(nameof(url));
            }
            var token = await _tokenSource.GetTokenAsync();

            var message = new HttpRequestMessage(method, url);

            message.Headers.Authorization = new AuthenticationHeaderValue(BearerHeader, token);

            message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(supportedMedia));

            return(message);
        }