Beispiel #1
0
        public void ProcessRequest(HttpContext context)
        {
            string respJson = string.Empty;

            Util util = new Util(SecretConstants.BASE_URL);

            AccessToken token = util.GetAccessToken(SecretConstants.CLIENT_ID,
                                                    SecretConstants.CLIENT_SECRET);


            if (context.Session["token"] == null)
            {
                string accessToken = token.access_token;
                if (accessToken == string.Empty)
                {
                    LogExtensions.Log("Authentication error");
                }
                context.Session["token"] = accessToken;
            }

            respJson = Newtonsoft.Json.JsonConvert.SerializeObject(token);

            context.Response.ContentType = "application/json";
            context.Response.Write(respJson);
        }
        // Util util = new Util(SecretConstants.BASE_URL);

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Util util = new Util(SecretConstants.BASE_URL);

                if (Session["token"] == null)
                {
                    string token = util.GetAccessToken(SecretConstants.CLIENT_ID,
                                                       SecretConstants.CLIENT_SECRET).access_token;
                    if (token == string.Empty)
                    {
                        LogExtensions.Log("Authentication error");
                    }
                    Session["token"] = token;
                }

                bool bucketExist = util.IsBucketExist(SecretConstants.DEFAULT_BUCKET_KEY, Session["token"].ToString());
                if (!bucketExist)
                {
                    util.CreateBucket(SecretConstants.DEFAULT_BUCKET_KEY, Session["token"].ToString());
                }
            }
        }