Exemplo n.º 1
0
 private void SetAuthenticationHeaders(
     System.Net.Http.Headers.HttpRequestHeaders headers,
     AuthorizationData auth)
 {
     headers.Add("x-xbl-contract-version", "2");
     headers.Add("Authorization", $"XBL3.0 x={auth.DisplayClaims.xui[0].uhs};{auth.Token}");
     headers.Add("Accept-Language", "en-US");
 }
Exemplo n.º 2
0
        private static void ReplaceAppToken(this System.Net.Http.Headers.HttpRequestHeaders headers)
        {
            const string name = "X-App-Token";

            _ = headers.Remove(name);
            headers.Add(name, GetCoolapkAppToken());
        }
Exemplo n.º 3
0
        private static void ReplaceRequested(this System.Net.Http.Headers.HttpRequestHeaders headers, string request)
        {
            const string name = "X-Requested-With";

            _ = headers.Remove(name);
            if (request != null)
            {
                headers.Add(name, request);
            }
        }
        public static void AddApiKeyAuthorizationHeader(this System.Net.Http.Headers.HttpRequestHeaders headers,
                                                        string clientID,
                                                        string secret,
                                                        DateTimeOffset utcNow,
                                                        TimeBasedTokenGenerator tokenGenerator = null)
        {
            tokenGenerator = tokenGenerator ?? _defaultTokenGenerator;

            string token = Microsoft.AspNetCore.WebUtilities.Base64UrlTextEncoder.Encode(tokenGenerator.ComputeToken(clientID, secret, utcNow));

            headers.Add("Authorization", $"TAPIKEY {clientID}:{token}");
        }
Exemplo n.º 5
0
        private bool AddAuthorizationError(System.Net.Http.Headers.HttpRequestHeaders headers, string errorMessage)
        {
            try
            {
                headers.Add("UnauthorizedMessage", errorMessage);
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Copies headers from one <see cref="System.Net.Http.HttpRequestMessage"/> instance to another.
        /// </summary>
        /// <param name="source">The source <see cref="System.Net.Http.HttpRequestMessage"/> to copy from.</param>
        /// <param name="destination">The destination <see cref="System.Net.Http.HttpRequestMessage"/> to copy to.</param>
        public static void CopyHeadersTo(this System.Net.Http.Headers.HttpRequestHeaders source, System.Net.Http.Headers.HttpRequestHeaders destination)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            foreach (var header in source)
            {
                if (destination.Contains(header.Key))
                {
                    destination.Remove(header.Key);
                }

                destination.Add(header.Key, header.Value);
            }
        }
Exemplo n.º 7
0
 public HttpRequestHeaders()
 {
     _headers = new HttpRequestMessage().Headers;
     _headers.Add("existing_simple_header", "existing_value");
     _headers.Add("existing_complex_header", new[] { "existing_value_01", "existing_value_02" });
 }
 public static void AddApiKeyAuthorizationHeader(this System.Net.Http.Headers.HttpRequestHeaders headers, string clientID, string secret)
 {
     secret = System.Net.WebUtility.UrlEncode(secret);
     headers.Add("Authorization", $"APIKEY {clientID}:{secret}");
 }