我没有测试过......但我会说 getToken 由于签名错误而不会得到任何结果......
如果没有用于对应用程序进行签名的证书的指纹,则无法在 google 开发者控制台中创建 oauth 客户端并结合包。
这就是为什么我会说如果恶意人员没有您的发布密钥库和私钥,getToken 不会收到任何关键信息
编辑:
PS:我知道...这仅回答您的一个问题...
edit2:
我已经对其进行了测试,并且可能会得到一个签名错误的有效令牌。如果 a 更改了签名,我得到以下异常:
03-17 18:08:05.195 3315-3498/org.example.myapp E/GoogleOAuthTask: Error getting token
com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission
at com.google.android.gms.auth.GoogleAuthUtil$1.zzam(Unknown Source)
at com.google.android.gms.auth.GoogleAuthUtil$1.zzan(Unknown Source)
at com.google.android.gms.auth.GoogleAuthUtil.zza(Unknown Source)
at com.google.android.gms.auth.GoogleAuthUtil.zza(Unknown Source)
at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
at org.example.myapp.shared.security.authentication.google.GoogleOAuthTask.doInBackground(GoogleOAuthTask.java:39)
at org.example.myapp.shared.security.authentication.google.GoogleOAuthTask.doInBackground(GoogleOAuthTask.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
然后我做了这样的事情来获得权限对话框:
try {
token = GoogleAuthUtil.getToken(context, emails[0], "oauth2:profile email");
GoogleAuthUtil.clearToken(context, token);
} catch (final UserRecoverableAuthException e) {
final Intent intent = e.getIntent();
context.startActivityForResult(intent, MyApplicationRequestCodes.SECURITY_OAUTH_PERMISSION);
} catch (final GoogleAuthException e) {
Log.e(LOG_TAG, "Error getting token", e);
} catch (final IOException e) {
Log.e(LOG_TAG, "Error getting token", e);
}
在对话框返回活动后,我做了这个:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(LOG_TAG, "returning from an activity. (requestCode=" + requestCode + ", resultCode=" + resultCode + ", data=" + data.toString() + ")");
if(requestCode == SECURITY_OAUTH_PERMISSION && resultCode == RESULT_OK) {
login();
}
if(requestCode == SECURITY_OAUTH_PERMISSION && resultCode == RESULT_CANCELED) {
authenticationHandler.onUserCanceled(new AuthenticationError(
AuthenticationErrorEnum.USER_ERROR,
"User closed permission dialog."
));
}
然后 login() 再次启动相同的过程,然后我收到一个 VALID 令牌,我可以再次验证另一个由 google 令牌保护的 API。在我的示例中,它是一个 firebase 数据库。
从firebase我得到了身份验证结果():
AuthData{uid='google:123412341234333', provider='google', token='***', expires='1458340206', auth='{uid=google: 123412341234333, provider=google}', providerData='{id=987234987032972034097234, accessToken=I_REMOVED_THE_TOKEN_STRING, displayName=Stefan Heimberg, email=kontakt@stefanheimberg.ch, cachedUserProfile={id= 987234987032972034097234, email=kontakt@stefanheimberg.ch, verified_email=true, name=Stefan Heimberg, given_name=Stefan, family_name=Heimberg, picture=https://lh4.googleusercontent.com/--XEA5G7LkjI/AAAAAAAAAAI/AAAAAAAAAAs/dpvdzBNpd6U/photo.jpg, locale=de}, profileImageURL=https://lh4.googleusercontent.com/--XEA5G7LkjI/AAAAAAAAAAI/AAAAAAAAAAs/dpvdzBNpd6U/photo.jpg}'}
所以,最后我必须说,即使签名与谷歌控制台中配置的不同,也可以获得有效的令牌。
但是在我更改签名之后,我的应用程序必须处理 com.google.android.gms.auth.UserRecoverableAuthException 并重新启动整个登录过程。