我正在尝试将我的应用程序生成的ZIP文件上传到用户的Google云端硬盘。 到目前为止,用户可以毫无问题地使用REST API登录Google。
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, REQUEST_CODE_GOOGLE_SIGN_IN);
但是我的App并非只为一个用户设计。 当下一个用户来到并生成自己的ZIP文件时,他可能想要使用自己的Google帐户登录并将该文件上传到自己的Google云端硬盘。 因此,我还实现了注销代码。
private void signOut() {
String currentGoogleAccountDisplayName = "";
if(mGoogleSignInClient == null) {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(mActivity.getApplicationContext());
if(account != null) {
currentGoogleAccountDisplayName = account.getDisplayName();
}
final String msg = "Revoke account \"" + currentGoogleAccountDisplayName + "\" access completed.";
mGoogleSignInClient.revokeAccess()
.addOnCompleteListener(this,
(@NonNull Task<Void> task) -> {
// Show sign-out message
});
}
但是Google似乎会缓存曾经登录过的帐户。 以后的用户可以通过简单地按其他用户的帐户而不用要求进行身份验证来登录以前的用户的Google帐户(在大多数情况下,输入密码)。 在这种情况下,用户可以将ZIP文件上传到以前用户的Google云端硬盘,这是严重的安全漏洞。
我尝试过
mGoogleSignInClient.revokeAccess();
和
mGoogleSignInClient.signOut();
他们都不要求以后的用户再次提供身份验证。
我还发现提到了一些答案
GoogleApiClient.clearDefaultAccountAndReconnect();
但是不建议使用此API。
.requestPassword()
中没有类似GoogleSignInOptions
的东西。
是否存在适当的方法来注销用户,并在每次尝试使用REST API再次登录时提示身份验证(即要求他输入密码)?
在这里找到类似的问题(但没有答案)- Ask for password when logging in using Google Sign-In API