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);
                    }
                }
            }
        }
        // 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());
        }
Exemple #3
0
        protected async void Page_Load(object sender, EventArgs e)
        {
            //*** Initialization
            divDropBoxAlert.Visible         = false;
            lnkbtnConnectDropBox.Visible    = false;
            lnkbtnDisconnectDropBox.Visible = false;
            divFileGrid.Visible             = false;
            pnlDownload.Visible             = false;

            //*** First Time
            if (!Page.IsPostBack)
            {
                //*** 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["returnBackURL"].ToString());

                    if (DropBoxConnector.MsgError == "")
                    {
                        //*** Get Token
                        Application["dropBoxAccessToken"] = DropBoxConnector.dropBoxAccessToken;
                    }
                    else   //*** If Error returned
                    {
                        lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                        //*** Show Error
                        divDropBoxAlert.Visible = true;
                    }
                }
                //******************************************************


                //*** Check dropBox Aurhentication Token
                if (Application["dropBoxAccessToken"] == null)
                {
                    //***************************
                    //*** access token is empty
                    //***************************
                    //*** 1. Check first for dropBox App Key & App secret
                    if (String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"]) ||
                        String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"]))
                    {
                        //*** Show Error Message
                        lblDropBoxMsg.Text = "Please set app key and secret in this project's Web.config file and restart. " +
                                             "App key/secret can be found in the Dropbox App Console, here: " +
                                             "https://www.dropbox.com/developers/apps";

                        //*** Show Error
                        divDropBoxAlert.Visible = true;

                        return;
                    }
                    else   //*** AppKey & secret exist
                    {
                        //*** Show Connect to DropBox button
                        lnkbtnConnectDropBox.Visible = true;
                    }
                }
                else
                {
                    //*** Get DropBox Client Object
                    Application["dropBoxClientObj"] = DropBoxConnector.getDropboxClient(Application["dropBoxAccessToken"].ToString());

                    if (DropBoxConnector.MsgError != "")    //*** If error
                    {
                        lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                        //*** Show Error
                        divDropBoxAlert.Visible = true;
                    }
                    else
                    {
                        //*** Get User Info
                        await DropBoxConnector.getUserInfo(Application["dropBoxClientObj"]);

                        lblAccountName.Text = DropBoxConnector.objDropBoxUser.AccountDisplayName;

                        DropBoxGridDataBind((List <string>)Session["FolderPath"]);
                    }
                }
            }
        }