0

I wonder if anyone can help. I'm using DropNet client and I've successfully authorized the app with Dropbox and I've stored the user token and secret within a SQL database so I can access them again as follows:

 public void Authenticated(Action success, Action<Exception> failure)
 {
        Client.GetAccessTokenAsync((accessToken) =>
        {
            UserToken = accessToken.Token;
            UserSecret = accessToken.Secret;

            UserAccountManagerBLL accBll = new UserAccountManagerBLL();
            accBll.RememberMe(UserToken, UserSecret, Email);

            if (success != null) success();
        },
        (error) =>
        {
            if (failure != null) failure(error);
        });

What I want to do is load the UserToken and UserSecret upon loading another form so I can drag and drop files and upload to Dropbox without having to authenticate the app with Dropbox all over again. Here's how I'm loading the token and secret:

private void DropTray_Load(object sender, EventArgs e)
{
        DropboxAccess dAccess = new DropboxAccess();

        UserAccountManagerBLL accMan = new UserAccountManagerBLL();

        UserToken = accMan.GetToken(Email);
        UserSecret= accMan.GetSecret(Email);

        if (UserToken == null && UserSecret == null)
        {
            MessageBox.Show(returnError());
        }
        else
        {
            Rectangle workingArea = Screen.GetWorkingArea(this);
            this.Location = new Point(workingArea.Right - Size.Width,
                                      workingArea.Bottom - Size.Height);

            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        }
}

This method is used to get the token

public string GetToken(string eMail)
{
        using (cxn = new SqlConnection(this.ConnectionString))
        {
            using (cmd = new SqlCommand("spGetDetails", cxn))
            {
                cmd.CommandType = CommandType.StoredProcedure;

                cxn.Open();
                SqlDataReader dReader = cmd.ExecuteReader();

                while (dReader.Read())
                {
                    Utoken = dReader["UserToken"].ToString();
                    break;
                }
                dReader.Close();
                cxn.Close();
            }
        }

        return Utoken;
}

Same for the secret

And once I have them, I have two properties that will hold these values upon page load:

    public string UserToken { get; set; }
    public string UserSecret { get; set; }

The problem is I don't know how to get DropNet to recognise these values I've loaded from the database and I can just start to drag and drop files!?

Update: here's where _Client gets the user token and secret for DropNet:

private DropNetClient _Client;
    public DropNetClient Client
    {
        get
        {
            if (_Client == null)
            {
                _Client = new DropNetClient(appKey, appSecret);

                if (IsAuthenticated)
                {
                    _Client.UserLogin = new UserLogin
                    {
                        Token = UserToken,
                        Secret = UserSecret
                    };
                }

                _Client.UseSandbox = true;
            }
            return _Client;
        }
    }

If anyone want's it, here's my repository....

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rob Gleeson
  • 315
  • 1
  • 5
  • 17
  • Setting the `UserLogin` object on the `DropNetClient` instance should be all you need to do. What are you seeing when you do this? – dkarzon Jun 06 '15 at 21:41
  • Hey Damian, Well when I load the form and try and upload a file via drag and drop it just fails. I wonder should I just say _Client.userLogin = new userLogin {token = UserToken, secret = UserToken}; on form load? – Rob Gleeson Jun 06 '15 at 21:46
  • Can you see what the API response is? Maybe use something like Fiddler to capture the web traffic. Also are you sure that code is being run at the correct time? ie, if falls into the `if (IsAuthenticated)` block and the `UserToken` and `UserSecret` are set correctly – dkarzon Jun 06 '15 at 22:06
  • Will check it out and give it a go! – Rob Gleeson Jun 06 '15 at 22:31

1 Answers1

0

SO I was almost there. It turns out all I had to do was create a new instance of DropNet client as opposed to a new UserLogin instance on the page load event!

        UserAccountManagerBLL accMan = new UserAccountManagerBLL();

        UserToken = accMan.GetToken(Email);
        UserSecret = accMan.GetSecret(Email);

        _Client = new DropNetClient(appKey, appSecret, UserToken, UserSecret);
Rob Gleeson
  • 315
  • 1
  • 5
  • 17