Example #1
0
        /// <summary>
        /// persist the Oauth access token in OauthAccessTokenStorage.xml file
        /// </summary>
        internal static void StoreOauthAccessToken(Page page)
        {
            string      path = page.Server.MapPath("/") + @"OauthAccessTokenStorage.xml";
            XmlDocument doc  = new XmlDocument();

            doc.Load(path);
            XmlNode      node = doc.CreateElement("record");
            XmlAttribute userMailIdAttribute = doc.CreateAttribute("usermailid");

            userMailIdAttribute.Value = page.Session["FriendlyEmail"].ToString();
            node.Attributes.Append(userMailIdAttribute);

            XmlAttribute accessKeyAttribute = doc.CreateAttribute("encryptedaccesskey");
            string       secuirtyKey        = ConfigurationManager.AppSettings["securityKey"];

            accessKeyAttribute.Value = CryptographyHelper.EncryptData(page.Session["accessToken"].ToString(), secuirtyKey);
            node.Attributes.Append(accessKeyAttribute);

            XmlAttribute encryptedaccesskeysecretAttribute = doc.CreateAttribute("encryptedaccesskeysecret");

            encryptedaccesskeysecretAttribute.Value = CryptographyHelper.EncryptData(page.Session["accessTokenSecret"].ToString(), secuirtyKey);
            node.Attributes.Append(encryptedaccesskeysecretAttribute);

            XmlAttribute realmIdAttribute = doc.CreateAttribute("realmid");

            realmIdAttribute.Value = page.Session["realm"].ToString();
            node.Attributes.Append(realmIdAttribute);

            XmlAttribute dataSourceAttribute = doc.CreateAttribute("dataSource");

            dataSourceAttribute.Value = page.Session["dataSource"].ToString();
            node.Attributes.Append(dataSourceAttribute);

            doc.DocumentElement.AppendChild(node);
            doc.Save(path);
        }