在 C# WinForms 应用程序中从数据库加载 DropNet 用户令牌和密码

Load DropNet user token and secret from a database in a C# WinForms application

不知道有没有人可以帮忙。我正在使用 DropNet 客户端,我已经使用 Dropbox 成功授权了该应用程序,并且我已经将用户令牌和密码存储在 SQL 数据库中,因此我可以按如下方式再次访问它们:

 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);
        });

我想做的是在加载另一个表单时加载 UserTokenUserSecret,这样我就可以拖放文件并上传到 Dropbox,而无需再次使用 Dropbox 验证应用程序.以下是我加载令牌和密码的方式:

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;
        }
}

此方法用于获取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;
}

同样的秘密

一旦我拥有它们,我就有两个属性将在页面加载时保存这些值:

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

问题是我不知道如何让 DropNet 识别我从数据库加载的这些值,我可以开始拖放文件!?

更新:这里是 _Client 获取 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....

所以我快到了。事实证明,我所要做的就是创建一个新的 DropNet 客户端实例,而不是在页面加载事件上创建一个新的 UserLogin 实例!

        UserAccountManagerBLL accMan = new UserAccountManagerBLL();

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

        _Client = new DropNetClient(appKey, appSecret, UserToken, UserSecret);