[英]Load DropNet user token and secret from a database in a C# WinForms application
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:
我正在使用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);
});
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. 我要做的是在加载另一种表单时加载
UserToken
和UserSecret
,这样我就可以拖放文件并上传到Dropbox,而无需再次通过Dropbox验证应用程序。 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!? 问题是我不知道如何让DropNet识别我从数据库中加载的这些值,我可以开始拖放文件!
Update: here's where _Client
gets the user token and secret for DropNet: 更新:在这里
_Client
获取_Client
的用户令牌和密码:
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.... 如果有人愿意,这是我的存储库。
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!
事实证明,我要做的就是在页面加载事件中创建一个新的DropNet客户端实例,而不是一个新的UserLogin实例!
UserAccountManagerBLL accMan = new UserAccountManagerBLL();
UserToken = accMan.GetToken(Email);
UserSecret = accMan.GetSecret(Email);
_Client = new DropNetClient(appKey, appSecret, UserToken, UserSecret);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.