コード例 #1
0
        public ConsentToken RefreshConsent(ConsentToken consent)
        {
            if (consent == null || consent.IsValid())
            {
                return(consent);
            }

            consent = this.windowsLiveLogin.RefreshConsentToken(consent);

            return(consent);
        }
コード例 #2
0
        private void HandleConsent()
        {
            //http://msdn.microsoft.com/en-us/library/cc287661.aspx

            ConsentToken consent = null;

            messengerApplication = new WindowsLiveMessenger(windowsLive);



            if (String.IsNullOrEmpty(this.Request.Params["ConsentToken"]))
            {
                if (WebConfigSettings.DebugWindowsLive)
                {
                    log.Info("usertoken was null");
                }
                consent = this.messengerApplication.HandleConsentResponse(this.Request.Params);
            }
            else
            {
                if (WebConfigSettings.DebugWindowsLive)
                {
                    log.Info("usertoken was not null");
                }
                consent = this.messengerApplication.DecodeToken(this.Request.Params["ConsentToken"]);
            }

            //the windows live id on the siteUser is I think the same thing as usertoken
            // it just needs to be decoded

            if (consent == null)
            {
                if (WebConfigSettings.DebugWindowsLive)
                {
                    log.Info("HandleConsentCompleted consent was null");
                }
                WebUtils.SetupRedirect(this, siteRoot);
                return;
            }

            if (WebConfigSettings.DebugWindowsLive)
            {
                if (consent.IsValid())
                {
                    log.Info("HandleConsent obtained valid consent");
                }
                else
                {
                    log.Info("HandleConsent obtained invalid consent");
                }
            }


            CookieHelper.SetCookie(consentTokenCookie, consent.Token);
            CookieHelper.SetCookie(delegationTokenCookie, consent.DelegationToken);


            SiteUser currentUser = SiteUtils.GetCurrentSiteUser();

            if ((currentUser != null) && (currentUser.UserGuid != Guid.Empty))
            {
                if (WebConfigSettings.DebugWindowsLive)
                {
                    log.Info("HandleConsent obtained siteUser");
                }

                currentUser.LiveMessengerId = consent.CID;
                currentUser.LiveMessengerDelegationToken = consent.Token;

                //if (!String.IsNullOrEmpty(Request.Params["ConsentToken"]))
                //{
                //    currentUser.LiveMessengerDelegationToken = Request.Params["ConsentToken"];
                //}

                currentUser.Save();

                if (WebConfigSettings.DebugWindowsLive)
                {
                    log.Info("HandleConsent saved CID " + consent.CID + " for user " + currentUser.Email + " " + currentUser.Name);
                }

                WebUtils.SetupRedirect(this, siteRoot + "/Secure/UserProfile.aspx");
                return;
            }

            if (WebConfigSettings.DebugWindowsLive)
            {
                log.Info("HandleConsent redirecting to site root");
            }


            WebUtils.SetupRedirect(this, siteRoot);
        }