コード例 #1
0
        /// <summary>
        /// Return an instance of Podio object
        /// </summary>
        /// <returns></returns>
        public static Podio GetClient()
        {
            /* SessionAuthStore is an implementation of PodioAPI.Utils.IAuthStore interface (stores OAuth data in DB)
             * You can do your own implementation of IAuthStore interface if you need to store access token in database or whereever,
             * and pass it in when you initialize Podio class
             */
            var dbAuthStore = new DbOAuthTokenStore();

            var podio = new Podio(ClientId, ClientSecret, dbAuthStore);

            if (HttpContext.Current.Session["UserId"] != null)
            {
                // If a userId is found in session, get the Sored token from database and set it to Podio object.
                var podioAuthData = new PodioOAuthData();
                var currentUserId = int.Parse(HttpContext.Current.Session["UserId"].ToString());

                var data = podioAuthData.GetbyUserId(currentUserId);
                if (data != null)
                {
                    var podioOAuthObject = JsonConvert.DeserializeObject <PodioOAuth>(data.OAuthJsonData);
                    podio.OAuth = podioOAuthObject;
                }
            }

            return(podio);
        }
コード例 #2
0
        //Store the PodioOAuth object in the db
        public void Set(PodioOAuth podioOAuth)
        {
            var jsonData       = JsonConvert.SerializeObject(podioOAuth);
            var podioOAuthData = new PodioOAuthData
            {
                UserId        = (int)podioOAuth.Ref.Id,
                OAuthJsonData = jsonData
            };

            podioOAuthData.Upsert();
        }