O login do Google obtém o token de acesso com o novo GoogleSignInOptions
No momento, meu aplicativo para Android usa o GoogleAuthUtil para fazer login de usuários e buscar umaccess_token
que é passado para o back-end (trechos de código abaixo dos quais mostram a criação do GoogleApiClient e o uso do GoogleAuthUtil para obter o token).
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope("profile"))
.build();
...
...
String accessToken = GoogleAuthUtil.getToken(GoogleLoginActivity.this,
Plus.AccountApi.getAccountName(mGoogleApiClient),
"oauth2:profile email");
que eu enviei para o back-end
Agora estou tentando mudar para o novo Login do Google -https://developers.google.com/identity/sign-in/android/sign-in
e alteramos a criação do GoogleApiClient como,
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken("<web client id>")
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
e depois fazer o login,
startActivityForResult(Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient), RC_GET_TOKEN);
e no uso do resultado da atividade (semelhante ao exemplo no link acima),
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (opr.isDone()) {
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
// and the GoogleSignInResult will be available instantly.
Log.d(TAG, "Got cached sign-in");
handleSignInResult(opr.get());
} else {
// If the user has not previously signed in on this device or the sign-in has expired,
// this asynchronous branch will attempt to sign in the user silently. Cross-device
// single sign-on will occur in this branch.
showProgress();
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(GoogleSignInResult googleSignInResult) {
hideProgress();
handleSignInResult(googleSignInResult);
}
});
}
mas agora parece que emhandleSingInResult(GoogleSignInResult result)
Eu só posso conseguir umid token
voltar comresult.getSignInAccount().getIdToken();
Alguém sabe se é possível obter um token de acesso a partir disso (como anteriormente) e, em caso afirmativo, como? Qualquer ajuda apreciada.