0
我能收到谷歌ID標記GoogleSignInAccount.getIdToken()
這樣,我對如何處理它幾個問題,谷歌ID令牌工作與Android
- 令牌約1KB string.I不能發送與每個服務器請求。那麼,如何才能在服務器端驗證它的正確方法是什麼?
- 我沒有看到刷新id令牌的方法。這是否會在GoogleSignInAccount類中自動發生?
- 谷歌方面對令牌驗證有任何限制(配額)嗎?
我能收到谷歌ID標記GoogleSignInAccount.getIdToken()
這樣,我對如何處理它幾個問題,谷歌ID令牌工作與Android
1.To不超載服務器我們決定以產生具有相同的到期時間內(短)的訪問令牌(1小時)
2.Token刷新可以再次調用登錄功能來實現:
private void loginGoogle(){
//context is Activity
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(context.getString(R.string.default_web_client_id)).requestEmail()
.build();
if (googleApiClient!=null) {
googleApiClient.stopAutoManage((FragmentActivity) context);
googleApiClient.disconnect();
}
googleApiClient = new GoogleApiClient.Builder(context)
.enableAutoManage((FragmentActivity) context, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.d("auth", "connection failed");
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
//
OptionalPendingResult<GoogleSignInResult> opr =
Auth.GoogleSignInApi.silentSignIn(googleApiClient);
if (opr.isDone()) {
GoogleSignInResult r = opr.get();
Log.d("auth", "google silent signin sync");
fillGoogleProfile(r.getSignInAccount());
} else {
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(@NonNull GoogleSignInResult result) {
Log.d("auth", "google silent signin async");
if (result.getSignInAccount()==null) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
//catch result in the onActivityResult
context.startActivityForResult(signInIntent, RC_SIGN_IN);
return;
}
fillGoogleProfile(result.getSignInAccount());
}
});
}
}
3.仍未找到答案