/// <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(); } }
/// <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); }
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); } }