private static string GetCookieValue(IInfrastructureAntiForgeryManager manager, HttpRequestHeaders headers)
        {
            var cookie = headers.GetCookies(manager.Configuration.TokenCookieName).LastOrDefault();

            if (cookie == null)
            {
                return(null);
            }
            return(cookie[manager.Configuration.TokenCookieName].Value);
        }
Ejemplo n.º 2
0
        public void GetCookies_GetsCookiesReturnsEmptyCollection()
        {
            // Arrange
            HttpRequestHeaders headers = CreateHttpRequestHeaders();

            // Act
            IEnumerable <CookieHeaderValue> cookies = headers.GetCookies();

            // Assert
            Assert.Equal(0, cookies.Count());
        }
Ejemplo n.º 3
0
        private static string GetCookieValue(string cookieName, HttpRequestHeaders headers)
        {
            var cookie = headers.GetCookies(cookieName).LastOrDefault();

            if (cookie == null)
            {
                return(null);
            }

            return(cookie[cookieName].Value);
        }
Ejemplo n.º 4
0
        public static string GetCookieValue(this HttpRequestHeaders requestHeaders, string cookieName)
        {
            var cookie = requestHeaders.GetCookies(cookieName).FirstOrDefault();

            if (cookie == null)
            {
                return(null);
            }

            return(cookie.Cookies.Where(item => item.Name == cookieName).Select(item => item.Value).FirstOrDefault());
        }
Ejemplo n.º 5
0
        public static string GetCookieValue(this HttpRequestHeaders headers, string cookieName)
        {
            var cookies = headers.GetCookies();

            if (cookies == null || !cookies.Any(c => c.Cookies.Any(k => k.Name == cookieName)))
            {
                return(null);
            }

            return(cookies.First(c => c[cookieName] != null)[cookieName].Value);
        }
Ejemplo n.º 6
0
        public string GetValueStorage(HttpRequestHeaders context, string key)
        {
            var cookie = context.GetCookies(key).FirstOrDefault();

            if (cookie != null)
            {
                return(cookie[key].Value);
            }

            return(null);
        }
        public static string GetCookie(HttpRequestHeaders headers, string name)
        {
            var cookies = headers.GetCookies(name).FirstOrDefault();

            if (cookies == null)
            {
                return(null);
            }
            var cookie = cookies.Cookies.SingleOrDefault(x => x.Name == name);

            return(cookie == null ? null : cookie.Value);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Validates the headers/cookies passed in for the request
        /// </summary>
        /// <param name="requestHeaders"></param>
        /// <param name="failedReason"></param>
        /// <returns></returns>
        public static bool ValidateHeaders(HttpRequestHeaders requestHeaders, out string failedReason)
        {
            var cookieToken = requestHeaders
                              .GetCookies()
                              .Select(c => c[CsrfValidationCookieName])
                              .FirstOrDefault();

            return(ValidateHeaders(
                       requestHeaders.ToDictionary(x => x.Key, x => x.Value).ToArray(),
                       cookieToken == null ? null : cookieToken.Value,
                       out failedReason));
        }
        /// <summary>Gets any cookie headers present in the request that contain a cookie state whose name that matches the specified value.</summary>
        /// <returns>A collection of <see cref="T:System.Net.Http.Headers.CookieHeaderValue" /> instances.</returns>
        /// <param name="headers">The request headers.</param>
        /// <param name="name">The cookie state name to match.</param>
        public static Collection <CookieHeaderValue> GetCookies(this HttpRequestHeaders headers, string name)
        {
            if (name == null)
            {
                throw Error.ArgumentNull("name");
            }
            IEnumerable <CookieHeaderValue> cookies = headers.GetCookies();

            CookieHeaderValue[] list = (
                from header in cookies
                where header.Cookies.Any((CookieState state) => string.Equals(state.Name, name, StringComparison.OrdinalIgnoreCase))
                select header).ToArray <CookieHeaderValue>();
            return(new Collection <CookieHeaderValue>(list));
        }
Ejemplo n.º 10
0
        public void GetCookies_GetsCookies(string expectedCookie)
        {
            // Arrange
            HttpRequestHeaders headers = CreateHttpRequestHeaders();

            headers.TryAddWithoutValidation("Cookie", expectedCookie);

            // Act
            IEnumerable <CookieHeaderValue> cookies = headers.GetCookies();

            // Assert
            Assert.Equal(1, cookies.Count());
            string actualCookie = cookies.ElementAt(0).ToString();

            Assert.Equal(expectedCookie, actualCookie);
        }
Ejemplo n.º 11
0
        public void GetCookiesByName_GetsCookies(IEnumerable <string> cookies, string name, IEnumerable <string> expectedCookies)
        {
            // Arrange
            HttpRequestHeaders headers = CreateHttpRequestHeaders();

            foreach (string cookie in cookies)
            {
                headers.TryAddWithoutValidation("Cookie", cookie);
            }

            // Act
            IEnumerable <CookieHeaderValue> actualCookieHeaderValues = headers.GetCookies(name);

            // Assert
            IEnumerable <string> actualCookies = actualCookieHeaderValues.Select(c => c.ToString());

            Assert.True(actualCookies.SequenceEqual(expectedCookies));
        }
Ejemplo n.º 12
0
 public static CookieHeaderValue GetSessionGuidFromCookies(HttpRequestHeaders requestHeaders)
 {
     return(requestHeaders.GetCookies(Constants.SessionIdKeyInCookies).FirstOrDefault());
 }
Ejemplo n.º 13
0
        public static Models.OpenIdToken TokenFromCookie(HttpRequestHeaders headers)
        {
            CookieHeaderValue sessionCookie = headers.GetCookies(TokenCookieName).FirstOrDefault();

            return(TokenFromCookie(sessionCookie[TokenCookieName].Values, true));
        }