protected async void Page_Load(object sender, EventArgs e) { //*** Check If it's called from Site Page if (Request.QueryString["Code"] == null) { //*** get access token Response.Redirect((DropBoxConnector.getAccessTokenURL(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], HttpContext.Current.Session["dropBoxReturnBackURL"].ToString())).ToLower(), false); } else //**** Get Code from Auth Provider { //*** Check If Code returned into Connection String if (Application["dropBoxAccessToken"] == null && !String.IsNullOrEmpty(Request.QueryString["Code"])) { //**** Initialize Session Folder Path List <string> Dump = new List <string> { }; Session["FolderPath"] = Dump; await DropBoxConnector.getAccessTokenFromResponse(Request.QueryString["Code"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], HttpContext.Current.Session["dropBoxReturnBackURL"].ToString().ToLower()); if (DropBoxConnector.MsgError == "") { //*** Get Token Application["dropBoxAccessToken"] = DropBoxConnector.dropBoxAccessToken; //**** Close & Refresh parent CodeReturned = "true"; } else //*** If Error returned { Response.Write(DropBoxConnector.MsgError); } } } }
//**** Connect to dropBox Button Handler protected void lnkbtnConnectDropBox_Click(object sender, EventArgs e) { if (HttpContext.Current.Session["returnBackURL"] == null) { HttpContext.Current.Session["returnBackURL"] = HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("?") <= 0 ? HttpContext.Current.Request.Url.AbsoluteUri.ToLower() : HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("?") + 1).ToLower(); } //*** get access token Response.Redirect(DropBoxConnector.getAccessTokenURL(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], HttpContext.Current.Session["returnBackURL"].ToString())); return; }
// GET: DropBoxAuth public async System.Threading.Tasks.Task <ActionResult> Index() { //*** Initlaize Session["CodeReturned"] = "false"; //*** Check If it's called from Site Page if (Request.QueryString["Code"] == null) { //*** get access token Response.Redirect((DropBoxConnector.getAccessTokenURL(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], Session["dropBoxReturnBackURL"].ToString())).ToLower(), false); } else //**** Get Code from Auth Provider { //*** Check If Code returned into Connection String if (Session["dropBoxAccessToken"] == null && !String.IsNullOrEmpty(Request.QueryString["Code"])) { //**** Initialize Session Folder Path List <string> Dump = new List <string> { }; Session["FolderPath"] = Dump; await DropBoxConnector.getAccessTokenFromResponse(Request.QueryString["Code"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], Session["dropBoxReturnBackURL"].ToString().ToLower()); if (DropBoxConnector.MsgError == "") { //*** Get Token Session["dropBoxAccessToken"] = DropBoxConnector.dropBoxAccessToken; //**** Close & Refresh parent Session["CodeReturned"] = "true"; } else //*** If Error returned { Response.Write(DropBoxConnector.MsgError); } } } return(View()); }