/// <summary>
        /// Create the HttpRequestMessage that will be used in accessing the Spring Cloud Configuration server
        /// </summary>
        /// <param name="requestUri">the Uri used when accessing the server</param>
        /// <returns>The HttpRequestMessage built from the path</returns>
        protected internal virtual HttpRequestMessage GetRequestMessage(string requestUri)
        {
            var request =
                HttpClientHelper.GetRequestMessage(HttpMethod.Get, requestUri, _settings.Username, _settings.Password);

            if (!string.IsNullOrEmpty(_settings.Token))
            {
                RenewToken(_settings.Token);
                request.Headers.Add(TokenHeader, _settings.Token);
            }

            return(request);
        }
示例#2
0
        public static HttpRequestMessage GetRequestMessage(HttpMethod method, string requestUri, Func <string> getAccessToken)
        {
            var requestMessage = HttpClientHelper.GetRequestMessage(method, requestUri, (string)null, (string)null);
            var parameter      = getAccessToken?.Invoke();

            if (parameter == null)
            {
                return(requestMessage);
            }
            var authenticationHeaderValue = new AuthenticationHeaderValue("Bearer", parameter);

            requestMessage.Headers.Authorization = authenticationHeaderValue;
            return(requestMessage);
        }