【发布时间】:2017-04-05 17:22:18
【问题描述】:
我正在尝试关注this tutorial。
我创建了这个 firebaseAuthWithGoogle 函数:
public void firebaseAuthWithGoogle(Activity context,FirebaseAuth mAuth, GoogleSignInAccount acct) {
Log.i(TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(context, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.i(TAG, "firebase signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.i(TAG, "firebase signInWithCredential" + task.getException());
}
// ...
}
});
}
我从这里打来的电话:
final GoogleSignInAccount acct = result.getSignInAccount();
AsyncTask asyncTask = new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
try{
String scope = "oauth2:" + Scopes.PROFILE;
Account account = new Account(acct.getEmail(), "com.google");
final String token = GoogleAuthUtil.getToken(PSSignInFlowActivity.this, account, scope); PSSocialService.getInstance().firebaseAuthWithGoogle(PSSignInFlowActivity.this, PSApplicationClass.getInstance().mAuth, acct);
}catch (Exception e){
Log.e("","firebase error trying to get client secret : " + e.getMessage());
}
return null;
}
};
asyncTask.execute();
我的 idToken 是:firebaseAuthWithGoogle:1024xxxxxxxxxxxxxx956(所以它不为空,添加它也许我没有发送我所支持的东西?)
但是当我调试时,我得到了这个错误:
Must specify an idToken or an accessToken.
我做错了什么?他们在教程中使用相同的逻辑
PS:如果重要的话,我在compile 'com.google.firebase:firebase-auth:10.2.0'
编辑:我注意到acct.getIdToken() 返回 null,这是为什么呢?
GoogleSignInAccount 不应该有 idToken 吗?
我正在注销acct.getId(),这是我在上面写的 1024xxxxxxxxxxxxx956。
EDIT2:我在我的 GSO 中添加了这个选项:
.requestIdToken(serverID)
现在我得到了 idToken,但我得到了这个响应:
04-05 10:34:16.388: I/PSSocialService(6285): firebase signInWithCredentialcom.google.firebase.FirebaseException: An internal error has occurred. [ Invalid Idp Response ]
serverID 是:264xxxxxxxxxx27.apps.googleusercontent.com 这是我应该使用的正确值吗? 在他们使用的教程中:
.requestIdToken(getString(R.string.default_web_client_id))
但我试过了,但它崩溃了,因为它说我需要使用相同的 clientID。
我将 serverID 用于.requestServerAuthCode(serverID),我想这就是原因
【问题讨论】:
标签: android firebase firebase-authentication access-token google-signin