【发布时间】:2014-05-03 19:03:23
【问题描述】:
目前,我正在将使用 oAuth 2.0 的 Google Drive API 与我的桌面应用程序集成。
我意识到,一段时间后,存储在磁盘上的Credential 将过期。发生这种情况时,我需要再次通过浏览器提示用户,要求他们输入用户名和密码。
public Pair<Pair<Credential, Userinfoplus>, Boolean> authorize(String userId) throws IOException {
try {
Credential credential = flow.loadCredential(userId);
if (credential != null
&& (credential.getRefreshToken() != null || credential.getExpiresInSeconds() > 60)) {
Userinfoplus userinfoplus = org.yccheok.jstock.google.Utils.getUserInfo(credential);
return new Pair<Pair<Credential, Userinfoplus>, Boolean>(new Pair<Credential, Userinfoplus>(credential, userinfoplus), true);
}
// open in browser
redirectUri = receiver.getRedirectUri();
由于用户将继续使用我的桌面应用程序数天、数周和数月,他们希望只提供一次用户名和密码。
有什么方法可以防止Credential 过期吗?我相信这是可以实现的,因为桌面版 Google 云端硬盘从不提示我输入用户名和密码。
【问题讨论】:
标签: java oauth-2.0 google-drive-api