예제 #1
0
        /// <summary>
        /// Step 2: Read the context and get the token.
        /// Then process consent and get the ConsentToken.
        /// Then set the cookie.
        /// </summary>
        /// <param name="context">The context of the application</param>
        public void SetToken()
        {
            // Extract the 'action' parameter, if any, from the request.
            string action = HttpContext.Current.Request["action"];

            if (action == "delauth")
            {
                //Attempt to extract the consent token from the response.
                WindowsLiveLogin.ConsentToken token = WindowsLiveLogin.ProcessConsent(HttpContext.Current.Request.Form);

                HttpCookie authCookietmp = new HttpCookie(AuthCookie);
                // If a consent token is found, store it in the cookie
                if (token != null)
                {
                    authCookietmp.Value   = token.Token;
                    authCookietmp.Expires = PersistCookie;
                }
                else
                {
                    authCookietmp.Expires = ExpireCookie;
                }

                HttpContext.Current.Response.Cookies.Add(authCookietmp);
                HttpContext.Current.Response.Redirect(contactsPageUrl);
                HttpContext.Current.Response.End();
            }
            else
            {
                HttpContext.Current.Response.End();
            }
        }
예제 #2
0
        private HttpWebResponse SendHttpRequest(WindowsLiveLogin.ConsentToken Token, ref string uriPath, string strRequestMethod)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriPath);

            request.Headers["Authorization"] = "DelegatedToken dt=\"" + Token.DelegationToken + "\"";
            request.Headers["Pragma"]        = "No-Cache";
            request.CookieContainer          = new CookieContainer();
            request.Method      = strRequestMethod;
            request.ContentType = "application/xml; charset=utf-8";

            return((HttpWebResponse)request.GetResponse());
        }
예제 #3
0
 /// <summary>
 /// The second step of the login phase.
 /// </summary>
 /// <param name="Session"> The current session. </param>
 /// <param name="Request"> The current request. </param>
 /// <param name="Server"> The current server utility. </param>
 /// <returns> True if the login was successful, otherwise false. </returns>
 public bool ProcessLogin(HttpSessionState Session, HttpRequest Request, HttpServerUtility Server)
 {
     if (Request["action"] == null)
     {
         return(false);
     }
     if (Request["action"] != "delauth")
     {
         return(false);
     }
     consent = wll.ProcessConsent(Request.Form);
     if (consent != null && consent.IsValid())
     {
         return(getContactsFromLive());
     }
     return(false);
 }
예제 #4
0
     protected void Page_Load(object sender, EventArgs e)
     {
         //Get the consent URL for the specified offers.
         ConsentUrl = wll.GetConsentUrl(Offers);
         
         HttpRequest req = HttpContext.Current.Request;
         HttpCookie authCookie = req.Cookies[AuthCookie];
 
         // If the raw consent token has been cached in a site cookie, attempt to
         // process it and extract the consent token.
         if (authCookie != null)
         {
             string t = authCookie.Value;
             Token = wll.ProcessConsentToken(t);
             getContacts(Token.DelegationToken,Token.LocationID);
             if ((Token != null) && !Token.IsValid())
             {
                 Token = null;
             }
         }
     }
예제 #5
0
        static void GetAuthHeader()
        {
            //TODO: replace this with scraping and return the right response values for the 4 variables
            //i.e.: call method ContactsAuthentication.AuthenticateContactsSharing(username, password)
            string responseConsentToken = "eact%3Duw5Ym5wpNL9Jo51f9N38Div7B9HmBTkwDof75T22MRvbToDeXSEYvZzWRuRMjHkw%252B8kbWcbKJ4ZwWdGcKm%252FeCJYCPIKTHMSCzx4gZscI9w21NKV%252BqjKFkQ6t9b6%252FccObokDfN6XCU1MBFddNoenuIAyo2o44luRpkDcokM3TgfSdtj%252Bg0hZUR8V8IIIvLmelc1KTjcI%252F3GJ2pBQXkxur0O4YKGu8cFF0y8gNVuXJvpL%252BcFq5%252Fdq8wMzTT6SnGbZgHyPqJv6UQZsYpC9EM%252FQmSlcxinLZf%252BV%252BxB25qNHE2GD05SFiUYKwEf%252FSS5a9RMziv8jThJTReCeFaBLbJClvGIr7D3zHh051REFWl97FlvH2oGcNMze5K9R%252Fxb9pi0%252BFcUCA6hTveVuyih0zOZY5TFyhvltaU2aemq3BBFOa%252FHRbTMu5kGAoW%252FUJiNf4FODvuZCF%252BrH%252BMMEV5V5b3WEsTPlytEG9HhzAjWpMV6i784pqXQjB7gF6Iuy2T8JKujk2wN%252FuFIS6F4Z%252BGMUbRYBxgmuLZMALShiscC6gC4JQuW7fr2zcTqBEmChmJAi9D9T97AVBWL5cyzrjxpkqm8Dr7z8KYqGcoWQ8VVy1JMcxW3vMGMJZPZBQUz1AOYut2xqd7kt1sssDfI7Owv4M7uU55K16IImxPR4LAmapujGLtTjWwfSoKYZBl2%252B41%252BuzPcvyUw%252BQqDu2aOCe1YuZ%252FaJry3tcIk43R0V9LFQ9HFEto8g8R7PeUlx9469jFhNPGPqzFy7Qlc%252BYGwf4nRwbrizAx5HKx9QuIcl%252FByK227CX0u7e7UkUzMQ%252FfTc13TpfvFk%252FBo5aXeoxjAKwrnyFeeDUKHiEsHwjwu2EW7kGfTdAOodUACDsoQDnrrrs%252BOX80Q4BzfVhZYy3F8XDAmdczqqzaGimQLK9UETvr%252F03GzCZdJResKRJNAeaaZ6Ahdy9ebJ64qvSvFq8jBOV1%252FY1rq8clX%252F5GZxnXzqT8gN%252F%252B9%252F8ktllYZi4QLmxaT2ChY2qnE8Fxx7GomY0k%252B5sDWhdqD18Ddu9HSFSaAFq4DflnTWis6jCLJ6WpqaeBGwJyPEGm0IYlVbQ0k7X5WnKYjKrC3kl68%252BqU6lL0T1nRoa8mZNXdeXZ72W%252FLQp21IrOH6NZhnomPBID2myyJ09QtuUkXlSaWbT5A0oRcE9ywPY4EvplbggyLxpke9jL%252BtIUQtNXdGN%252B%252FwjQhREw8dfMRHoRl6VN%252BmGLONeVvoR6Lvi%252BXJZhBz36XwwfhXtGb7kKIud8E9as%252FMC6YZcUNBn%252F28Zj9YdcRmM2iAAs9DBvw5tTmgAfPYU%253D";
            string responseResponseCode = "RequestApproved";
            string responseAction       = "delauth";
            string responseAppctx       = "";

            NameValueCollection nvc = new NameValueCollection(4);
            WindowsLiveLogin    wll = new WindowsLiveLogin(appId, secretKey);

            nvc.Add("ConsentToken", responseConsentToken);
            nvc.Add("ResponseCode", responseResponseCode);
            nvc.Add("action", responseAction);
            nvc.Add("appctx", responseAppctx);

            WindowsLiveLogin.ConsentToken ct = wll.ProcessConsent(nvc);
            authHeader = String.Format("DelegatedToken dt=\"{0}\"", ct.DelegationToken);
            lid        = ct.LocationID;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Get the consent URL for the specified offers.
            try
            {
                ConsentUrl = wll.GetConsentUrl(Offers);

                var action = Request["action"];

                if (action == "delauth")
                {
                    //Attempt to extract the consent token from the response.
                    var token = wll.ProcessConsent(Request.Form);

                    var authCookie = new HttpCookie(AuthCookie);
                    // If a consent token is found, store it in the cookie and then
                    // redirect to the main page.
                    if (token != null)
                    {
                        authCookie.Value   = token.Token;
                        authCookie.Expires = PersistCookie;
                    }
                    else
                    {
                        authCookie.Expires = ExpireCookie;
                    }

                    Response.Cookies.Add(authCookie);
                    Response.Redirect(Request.GetUrlRewriter().OriginalString, true);
                }
                else
                {
                    var req        = HttpContext.Current.Request;
                    var authCookie = req.Cookies[AuthCookie];

                    // If the raw consent token has been cached in a site cookie, attempt to
                    // process it and extract the consent token.
                    if (authCookie != null)
                    {
                        var t = authCookie.Value;
                        Token = wll.ProcessConsentToken(t);
                        if ((Token != null) && !Token.IsValid())
                        {
                            Token = null;
                            Response.Redirect(ConsentUrl);
                        }
                        if (Token != null)
                        {
                            ProcessContacts();
                        }
                    }
                    else
                    {
                        Response.Redirect(ConsentUrl);
                    }
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                SubmitError(ex.Message);
            }
        }
예제 #7
0
        private IList <IContact> GetContacts(int pageNumber, int pageSize, ISelection selection)
        {
            HttpWebResponse response;

            authCookie = HttpContext.Current.Request.Cookies["delauthtoken"];
            IList <IContact> result = new List <IContact>();

            if (authCookie != null)
            {
                string t = authCookie.Value;
                WindowsLiveLogin.ConsentToken Token = WindowsLiveLogin.ProcessConsentToken(t);

                if ((Token != null) && Token.IsValid())
                {
                    ServicePointManager.ServerCertificateValidationCallback +=
                        delegate(object sender, X509Certificate certificate, X509Chain chain,
                                 SslPolicyErrors sslPolicyErrors)
                    {
                        bool validationResult = true;
                        return(validationResult);
                    };

                    UriBuilder uriBuilder = new UriBuilder();
                    uriBuilder.Scheme = "HTTPS";
                    uriBuilder.Path   = "/users/@L@" + Token.LocationID + "/rest/invitationsbyemail";
                    uriBuilder.Host   = "livecontacts.services.live.com";
                    uriBuilder.Port   = 443;
                    string uriPath = uriBuilder.Uri.AbsoluteUri;

                    response = SendHttpRequest(Token, ref uriPath, "GET");

                    if (response != null && response.ContentLength != 0)
                    {
                        XmlDocument   doc    = new XmlDocument();
                        XmlTextReader reader = new XmlTextReader(response.GetResponseStream());
                        reader.Read();
                        // load reader
                        doc.Load(reader);
                        int i = 1;
                        if (pageNumber > 0)
                        {
                            foreach (XmlNode node in doc.SelectNodes(@"/LiveContacts/Contacts/Contact"))
                            {
                                if (i < (pageNumber * pageSize) - (pageSize - 1))
                                {
                                    i++;
                                    continue;
                                }
                                if (i > (pageNumber * pageSize))
                                {
                                    break;
                                }
                                GetContact(i++, node, result);
                            }
                            TotalCount = doc.SelectNodes(@"/LiveContacts/Contacts/Contact").Count;
                        }
                        else if (selection != null)
                        {
                            foreach (XmlNode node in doc.SelectNodes(@"/LiveContacts/Contacts/Contact"))
                            {
                                if (!selection.SelectedAll && !selection.SelectedIndexs.Exists(delegate(int record) { if (record == i)
                                                                                                                      {
                                                                                                                          return(true);
                                                                                                                      }
                                                                                                                      return(false); }))
                                {
                                    i++;
                                    continue;
                                }
                                if (selection.SelectedAll && selection.SelectedIndexs.Exists(delegate(int record) { if (record == i)
                                                                                                                    {
                                                                                                                        return(true);
                                                                                                                    }
                                                                                                                    return(false); }))
                                {
                                    i++;
                                    continue;
                                }

                                Contact contact = new Contact();
                                contact.Index = i;
                                if (node.ChildNodes.Count > 0 && node.ChildNodes[0].ChildNodes.Count > 0 &&
                                    node.ChildNodes[0].ChildNodes[0].ChildNodes.Count > 0)
                                {
                                    contact.FirstName = node.ChildNodes[0].ChildNodes[0].ChildNodes[0].InnerText;
                                }
                                if (node.ChildNodes.Count > 0 && node.ChildNodes[0].ChildNodes.Count > 0 &&
                                    node.ChildNodes[0].ChildNodes[0].ChildNodes.Count > 1)
                                {
                                    contact.LastName = node.ChildNodes[0].ChildNodes[0].ChildNodes[1].InnerText;
                                }
                                if (node.ChildNodes.Count > 1)
                                {
                                    contact.Email = node.ChildNodes[1].InnerText;
                                }
                                result.Add(contact);
                                i++;
                            }
                        }
                        else
                        {
                            foreach (XmlNode node in doc.SelectNodes(@"/LiveContacts/Contacts/Contact"))
                            {
                                GetContact(i++, node, result);
                            }
                            TotalCount = doc.SelectNodes(@"/LiveContacts/Contacts/Contact").Count;
                        }
                    }
                    response.Close();
                }
            }
            return(result);
        }