0
我試圖存儲用戶令牌,一旦我的應用程序被授權與Dropbox,以便當我打開一個不同的表單(這將具有拖放功能),用戶不會必須再次授權應用程序,並能夠執行Dropbox的上傳功能。使用DropNet從Dropbox存儲用戶令牌
我用於授權的Dropbox類DropNet是:
我宣佈兩個屬性; public string UserToken { get; set; }
和public string UserSecret { get; set; }
string appKey = "APP_KEY";
string appSecret = "APP_SECRET";
public bool LinkDrpbox()
{
bool dropboxLink = false;
Authenticate(
url =>
{
var proc = Process.Start("iexplore.exe", url);
proc.WaitForExit();
Authenticated(
() =>
{
dropboxLink = true;
},
exc => ShowException(exc));
},
ex => dropboxLink = false);
if (dropboxLink)
{
return true;
}
else
{
return false;
}
}
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;
}
}
public bool IsAuthenticated
{
get
{
return UserToken != null &&
UserSecret != null;
}
}
public void Authenticate(Action<string> success, Action<Exception> failure)
{
Client.GetTokenAsync(userLogin =>
{
var url = Client.BuildAuthorizeUrl(userLogin);
if (success != null) success(url);
}, error =>
{
if (failure != null) failure(error);
});
}
public void Authenticated(Action success, Action<Exception> failure)
{
Client.GetAccessTokenAsync((accessToken) =>
{
UserToken = accessToken.Token;
UserSecret = accessToken.Secret;
if (success != null) success();
},
(error) =>
{
if (failure != null) failure(error);
});
}
private void ShowException(Exception ex)
{
string error = ex.ToString();
}
}
我可以授權我的應用程序,但我不能確定如何保存訪問令牌。我假設在app.config
文件但不確定。
任何幫助,將不勝感激!
可能需要更多信息,即。你在哪個平臺上?網?的WinForms? WPF? – dkarzon
啊WinForms .... –
你想存儲多久的令牌?會議?跨應用關閉/打開?用戶資料? – dkarzon