public override YahooSession LoadSession()
        {
            YahooSession yahooSession = null;
            if (HttpContext.Current.Session != null &&
                HttpContext.Current.Session["YahooSession"] != null)
            {
                yahooSession = HttpContext.Current.Session["YahooSession"] as YahooSession;
            }

            // Load from XML when not found in the Session
            if (yahooSession == null)
            {
                yahooSession = new YahooSession();
                DataSet authenticationState = LoadAuthenticationState();
                if (authenticationState != null)
                {
                    DataRow row = GetYahooSessionRow(authenticationState);
                    if (row != null)
                    {
                        yahooSession.ApplicationId = row["ApplicationId"] as String;
                        yahooSession.Token = row["Token"] as String;
                        yahooSession.ApplicationData = row["ApplicationData"] as String;
                        yahooSession.LoginDate = (DateTime) row["LoginDate"];
                        yahooSession.ValidUntil = (DateTime)row["ValidUntil"];
                        if (yahooSession.ValidUntil > DateTime.Now &&
                            !String.IsNullOrEmpty(yahooSession.Token))
                        {
                            yahooSession.UpdateCredentials();
                        }
                        if (HttpContext.Current.Session != null)
                        {
                            HttpContext.Current.Session["YahooSession"] = yahooSession;
                        }
                    }
                }
            }

            return yahooSession;
        }
        public override void SaveSession(YahooSession yahooSession)
        {
            if (HttpContext.Current.Session != null &&
               HttpContext.Current.Session["YahooSession"] == null)
            {
                HttpContext.Current.Session["YahooSession"] = yahooSession;
            }

            // protected against concurrency
            lock (padLock)
            {
                DataSet authenticationState = LoadAuthenticationState();
                if (authenticationState == null)
                {
                    authenticationState = CreateAuthenticationState();
                }

                DataRow row = GetYahooSessionRow(authenticationState);
                if (row == null)
                {
                    DataRow dRow = authenticationState.Tables[YahooSessionsTable].NewRow();
                    dRow["UserID"] = UserID;
                    dRow["ApplicationID"] = yahooSession.ApplicationId;
                    dRow["Token"] = yahooSession.Token;
                    dRow["ApplicationData"] = yahooSession.ApplicationData;
                    dRow["LoginDate"] = yahooSession.LoginDate;
                    dRow["ValidUntil"] = yahooSession.ValidUntil;
                    dRow["CreationDate"] = DateTime.Now;
                    dRow["ModifiedDate"] = DateTime.Now;
                    authenticationState.Tables[YahooSessionsTable].Rows.Add(dRow);
                }
                else
                {
                    row["ApplicationID"] = yahooSession.ApplicationId;
                    row["Token"] = yahooSession.Token;
                    row["ApplicationData"] = yahooSession.ApplicationData;
                    row["LoginDate"] = yahooSession.LoginDate;
                    row["ValidUntil"] = yahooSession.ValidUntil;
                    row["ModifiedDate"] = DateTime.Now;
                }

                // write out changes
                StreamWriter xmlSW = new StreamWriter(AuthenticationStateFileName);
                authenticationState.WriteXml(xmlSW, XmlWriteMode.WriteSchema);
                xmlSW.Close();
            }
        }
Ejemplo n.º 3
0
        private void InitializeYahooSession()
        {
            try
            {
                HttpContext context = HttpContext.Current;
                if (!String.IsNullOrEmpty(context.Request.QueryString["token"]) &&
                    !String.IsNullOrEmpty(context.Request.QueryString["appid"]))
                {
                    YahooSession yahooSession = YahooAuthenticationProvider.Instance.LoadSession();

                    string signedUrl = YahooConfiguration.ApplicationEntryPoint + context.Request.Url.Query;
                    if (yahooSession.Authentication.IsValidSignedUrl(
                            new Uri(signedUrl), YahooConfiguration.SharedSecret))
                    {
                        Logger.Debug("Successful Login!");

                        string destinationUrl = YahooConfiguration.ApplicationEntryPoint;
                        string localUrl;

                        Dictionary <String, String> appData =
                            ParseApplicationData(context.Request.QueryString["appdata"]);

                        if (appData.ContainsKey("vslocal") &&
                            "true".Equals(appData["vslocal"]))
                        {
                            localUrl = String.Format("http://localhost:{0}/{1}/",
                                                     appData["port"], appData["virtdir"]);
                            if ("localhost".Equals(context.Request.Url.Host))
                            {
                                destinationUrl = localUrl;
                            }
                            else
                            {
                                destinationUrl = localUrl + context.Request.Url.Query;
                            }
                        }

                        yahooSession.Authentication.Token =
                            context.Request.QueryString["token"];
                        yahooSession.Authentication.ApplicationId =
                            context.Request.QueryString["appid"];
                        context.Session["YahooApplicationData"] =
                            context.Request.QueryString["appdata"];

                        yahooSession.Authentication.UpdateCredentials();
                        yahooSession.LoginDate = DateTime.Now;

                        YahooAuthenticationProvider.Instance.SaveSession(yahooSession);

                        Logger.Debug("destinationUrl: " + destinationUrl);
                        context.Response.Redirect(destinationUrl, true);
                    }
                    else
                    {
                        Logger.Warn("Url not valid for Yahoo BBAuth: " + context.Request.Url);
                    }
                }
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    Logger.Error(ex.Message, ex);
                }
            }
        }
 public override void SaveSession(YahooSession yahooSession)
 {
     throw new NotImplementedException();
 }
 public abstract void SaveSession(YahooSession yahooSession);