GetCookieContainer() публичный Метод

public GetCookieContainer ( ) : Task
Результат Task
Пример #1
0
        public static async Task <bool> Create(Uri spSiteUrl, string username, string password, bool useIntegratedWindowsAuth, bool verbose)
        {
            var             utility = new SpoAuthUtility(spSiteUrl, username, password, useIntegratedWindowsAuth, verbose);
            CookieContainer cc      = await utility.GetCookieContainer();

            var cookies = from Cookie c in cc.GetCookies(spSiteUrl) where c.Name == "FedAuth" select c;

            if (cookies.Count() > 0)
            {
                current = utility;
                return(true);
            }
            else
            {
                throw new Exception("Could not retrieve Auth cookies");
            }
        }
        /// <summary>
        /// Sends a JSON OData request appending SPO auth cookies to the request header.
        /// </summary>
        /// <param name="uri">The request uri</param>
        /// <param name="method">The http method</param>
        /// <param name="requestContent">A stream containing the request content</param>
        /// <param name="clientHandler">The request client handler</param>
        /// <param name="authUtility">An instance of the auth helper to perform authenticated calls to SPO</param>
        /// <param name="headers">The http headers to append to the request</param>
        public static async Task <byte[]> SendODataJsonRequest(Uri uri, HttpMethod method, Stream requestContent, HttpClientHandler clientHandler, SpoAuthUtility authUtility, Dictionary <string, string> headers = null)
        {
            if (clientHandler.CookieContainer == null)
            {
                clientHandler.CookieContainer = new CookieContainer();
            }

            CookieContainer cookieContainer = await authUtility.GetCookieContainer(); // get the auth cookies from SPO after authenticating with Microsoft Online Services STS

            foreach (Cookie c in cookieContainer.GetCookies(uri))
            {
                clientHandler.CookieContainer.Add(uri, c); // apppend SPO auth cookies to the request
            }

            return(await SendHttpRequest(
                       uri,
                       method,
                       requestContent,
                       "application/json;odata=verbose;charset=utf-8", // the http content type for the JSON flavor of SP REST services
                       clientHandler,
                       headers));
        }
Пример #3
0
        /// <summary>
        /// Sends a JSON OData request appending SPO auth cookies to the request header.
        /// </summary>
        /// <param name="uri">The request uri</param>
        /// <param name="method">The http method</param>
        /// <param name="requestContent">A stream containing the request content</param>
        /// <param name="clientHandler">The request client handler</param>
        /// <param name="authUtility">An instance of the auth helper to perform authenticated calls to SPO</param>
        /// <param name="headers">The http headers to append to the request</param>
        public static async Task<byte[]> SendODataJsonRequest(Uri uri, HttpMethod method, Stream requestContent, HttpClientHandler clientHandler, SpoAuthUtility authUtility, Dictionary<string, string> headers = null)
        {
            if (clientHandler.CookieContainer == null)
                clientHandler.CookieContainer = new CookieContainer();

            CookieContainer cookieContainer = await authUtility.GetCookieContainer(); // get the auth cookies from SPO after authenticating with Microsoft Online Services STS

            foreach (Cookie c in cookieContainer.GetCookies(uri))
            {
                clientHandler.CookieContainer.Add(uri, c); // apppend SPO auth cookies to the request
            }

            return await SendHttpRequest(
                uri, 
                method, 
                requestContent, 
                "application/json;odata=verbose;charset=utf-8", // the http content type for the JSON flavor of SP REST services 
                clientHandler, 
                headers);
        }
Пример #4
0
 public static async Task<bool> Create(Uri spSiteUrl, string username, string password, bool useIntegratedWindowsAuth, bool verbose)
 {
     var utility = new SpoAuthUtility(spSiteUrl, username, password, useIntegratedWindowsAuth,verbose);
     CookieContainer cc = await utility.GetCookieContainer();
     var cookies = from Cookie c in cc.GetCookies(spSiteUrl) where c.Name =="FedAuth" select c;
     if (cookies.Count() > 0)
     {
         current = utility;
         return true;
     }
     else
         throw new Exception("Could not retrieve Auth cookies");
 }