Example #1
0
        public MessengerTicket CreateSignedTicket(string consentToken, params string[] cids)
        {
            if (String.IsNullOrEmpty(consentToken))
            {
                return(null);
            }

            ConsentToken consent = this.DecodeToken(consentToken);

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

            ApplicationContactList list = new ApplicationContactList();
            string ticket = list.CreateApplicationContactList(
                consent.CID,
                cids);

            string signature = list.SignApplicationContactList(
                ticket,
                consent.SessionKey);

            return(new MessengerTicket(ticket, signature));
        }
        private void PopulateMessenger()
        {
            if (WebConfigSettings.GloballyDisableMemberUseOfWindowsLiveMessenger)
            {
                return;
            }
            if (!siteSettings.AllowWindowsLiveMessengerForMembers)
            {
                return;
            }
            if (siteUser == null)
            {
                return;
            }
            if (!siteUser.EnableLiveMessengerOnProfile)
            {
                return;
            }
            if (siteUser.LiveMessengerId.Length == 0)
            {
                return;
            }

            divLiveMessenger.Visible = true;
            chat1.Invitee            = siteUser.LiveMessengerId;
            //chat1.InviteeDisplayName = siteUser.Name;

            if (WebConfigSettings.TestLiveMessengerDelegation)
            {
                WindowsLiveLogin     wl             = WindowsLiveHelper.GetWindowsLiveLogin();
                WindowsLiveMessenger m              = new WindowsLiveMessenger(wl);
                ConsentToken         token          = m.DecodeToken(siteUser.LiveMessengerDelegationToken);
                ConsentToken         refreshedToken = m.RefreshConsent(token);
                if (refreshedToken != null)
                {
                    chat1.DelegationToken = refreshedToken.DelegationToken;
                    string signedParams = WindowsLiveMessenger.SignParameters(
                        refreshedToken.SessionKey,
                        siteUser.Name,
                        string.Empty,
                        string.Empty);
                    chat1.SignedParams = signedParams;
                }
                else
                {
                    //chat1.DelegationToken = siteUser.LiveMessengerDelegationToken;
                    chat1.DelegationToken = token.DelegationToken;
                    string signedParams = WindowsLiveMessenger.SignParameters(
                        token.SessionKey,
                        siteUser.Name,
                        string.Empty,
                        string.Empty);

                    chat1.SignedParams = signedParams;
                }
            }
        }
Example #3
0
        public ConsentToken RefreshConsent(ConsentToken consent)
        {
            if (consent == null || consent.IsValid())
            {
                return(consent);
            }

            consent = this.windowsLiveLogin.RefreshConsentToken(consent);

            return(consent);
        }
Example #4
0
        private void DoExistingUserLogic(Guid userGuid)
        {
            // user found so login if allowed
            SiteUser user = new SiteUser(siteSettings, userGuid);

            bool canLogin = true;

            if (
                (siteSettings.UseSecureRegistration) &&
                (user.RegisterConfirmGuid != Guid.Empty)
                )
            {
                Notification.SendRegistrationConfirmationLink(
                    SiteUtils.GetSmtpSettings(),
                    ResourceHelper.GetMessageTemplate("RegisterConfirmEmailMessage.config"),
                    siteSettings.DefaultEmailFromAddress,
                    user.Email,
                    siteSettings.SiteName,
                    WebUtils.GetSiteRoot() + "/ConfirmRegistration.aspx?ticket=" +
                    user.RegisterConfirmGuid.ToString());


                log.Info("User " + user.Name + " tried to login but email address is not confirmed.");

                canLogin = false;
            }

            if (user.IsLockedOut)
            {
                log.Info("User " + user.Name + " tried to login but account is locked.");

                canLogin = false;
            }

            if (canLogin)
            {
                if (siteSettings.UseEmailForLogin)
                {
                    FormsAuthentication.SetAuthCookie(
                        user.Email, persistCookie);
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(
                        user.LoginName, persistCookie);
                }

                if (user.LiveMessengerDelegationToken.Length > 0)
                {
                    WindowsLiveMessenger m     = new WindowsLiveMessenger(windowsLive);
                    ConsentToken         token = m.DecodeToken(user.LiveMessengerDelegationToken);
                    token = m.RefreshConsent(token);
                    if (token != null)
                    {
                        CookieHelper.SetCookie(consentTokenCookie, token.Token);
                        CookieHelper.SetCookie(delegationTokenCookie, token.DelegationToken);
                    }
                }

                if (WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites)
                {
                    string cookieName = "siteguid" + siteSettings.SiteGuid;
                    CookieHelper.SetCookie(cookieName, user.UserGuid.ToString(), persistCookie);
                }

                user.UpdateLastLoginTime();

                // track user ip address
                UserLocation userLocation = new UserLocation(user.UserGuid, SiteUtils.GetIP4Address());
                userLocation.SiteGuid = siteSettings.SiteGuid;
                userLocation.Hostname = Page.Request.UserHostName;
                userLocation.Save();

                string redirectUrl = GetRedirectPath();
                CookieHelper.ExpireCookie(returnUrlCookieName);

                UserSignInEventArgs u = new UserSignInEventArgs(user);
                OnUserSignIn(u);

                //WebUtils.SetupRedirect(this, redirectUrl);
                Response.Redirect(redirectUrl);
                return;
            }
            else
            {
                // redirect to login
                // need to make login page show
                // reason for failure
                //WebUtils.SetupRedirect(this, LoginPage);
                Response.Redirect(LoginPage);
            }
        }
Example #5
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);
        }