protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var client = new HawkClient(options);
            await client.CreateClientAuthorizationAsync(new WebApiRequestMessage(request));

            var response = await base.SendAsync(request, cancellationToken);
            var responseMessage = new WebApiResponseMessage(response);

            if (!await client.AuthenticateAsync(responseMessage))
                throw new SecurityException("Invalid Mac and/or hash. Response possibly tampered.");

            return response;
        }
Example #2
0
        protected async override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var client = new HawkClient(options);
            await client.CreateClientAuthorizationAsync(new WebApiRequestMessage(request));

            var response = await base.SendAsync(request, cancellationToken);

            var responseMessage = new WebApiResponseMessage(response);

            if (!await client.AuthenticateAsync(responseMessage))
            {
                throw new SecurityException("Invalid Mac and/or hash. Response possibly tampered.");
            }

            return(response);
        }
        protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var client = new HawkClient(options);
            await client.CreateClientAuthorizationAsync(new WebApiRequestMessage(request));

            var response = await base.SendAsync(request, cancellationToken);
            var responseMessage = new WebApiResponseMessage(response);

            HawkEventSource.Log.Debug(String.Format("Response received with status of {0}", (int)responseMessage.StatusCode));

            if (!await client.AuthenticateAsync(responseMessage))
            {
                string header = responseMessage.Headers.FirstOrDefault(HawkConstants.ServerAuthorizationHeaderName);
                HawkEventSource.Log.ServerResponse((int)responseMessage.StatusCode, await responseMessage.ReadBodyAsStringAsync(), header ?? String.Empty);

                throw new SecurityException("Invalid Mac and/or hash. Response possibly tampered.");
            }

            return response;
        }
        protected async override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var client = new HawkClient(options);
            await client.CreateClientAuthorizationAsync(new WebApiRequestMessage(request));

            var response = await base.SendAsync(request, cancellationToken);

            var responseMessage = new WebApiResponseMessage(response);

            HawkEventSource.Log.Debug(String.Format("Response received with status of {0}", (int)responseMessage.StatusCode));

            if (!await client.AuthenticateAsync(responseMessage))
            {
                string header = responseMessage.Headers.FirstOrDefault(HawkConstants.ServerAuthorizationHeaderName);
                HawkEventSource.Log.ServerResponse((int)responseMessage.StatusCode, await responseMessage.ReadBodyAsStringAsync(), header ?? String.Empty);

                throw new SecurityException("Invalid Mac and/or hash. Response possibly tampered.");
            }

            return(response);
        }