示例#1
0
        async Task <HttpResponseMessage> IProxyRelayCallService.ProxyRelayCallAsync(string tenantId, string body, HttpMethod httpMethod, IHeaderDictionary httpHeaders, string url)
        {
            if (string.IsNullOrWhiteSpace(body))
            {
                throw new ArgumentNullException(nameof(body));
            }
            if (string.IsNullOrWhiteSpace(tenantId))
            {
                throw new ArgumentNullException(nameof(tenantId));
            }
            if (string.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (httpMethod is null)
            {
                throw new ArgumentNullException(nameof(httpMethod));
            }

            HybridConnectionDto hybridConnectionDto = await _storageApiClient.GetRelayFromIdAsync(tenantId);

            if (hybridConnectionDto is null)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            var relayCallDto = new RelayCallDto(hybridConnectionDto, body, httpMethod, httpHeaders, url);

            return(await _relayApiClient.RelayCallAsync(relayCallDto));
        }
示例#2
0
        private async Task SetupHttpClientAsync(RelayCallDto relayCallDto)
        {
            PolicyDto policyDto     = relayCallDto.HybridConnection.PolicyDtos.First(x => x.PolicyType == PolicyClaim.Send);
            var       tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(policyDto.PolicyName, policyDto.PolicyKey);
            var       token         = (await tokenProvider.GetTokenAsync(relayCallDto.HybridConnection.HybridConnectionUrl.AbsoluteUri, TimeSpan.FromHours(1))).TokenString;

            _httpClient.DefaultRequestHeaders.Add("ServiceBusAuthorization", token);
        }
示例#3
0
        async Task <HttpResponseMessage> IRelayApiClient.RelayCallAsync(RelayCallDto relayCallDto)
        {
            await SetupHttpClientAsync(relayCallDto);

            var request = new HttpRequestMessage(relayCallDto.HttpMethod, new Uri(relayCallDto.HybridConnection.HybridConnectionUrl, $"?url=relayCallDto.Url"))
            {
                Content = new StringContent(relayCallDto.BodyContent)
            };

            HttpResponseMessage response = await _httpClient.SendAsync(request);

            return(response);
        }