gpt4 book ai didi

android - Google 登录(使用 Firebase)突然停止工作?

转载 作者:行者123 更新时间:2023-11-29 19:15:23 26 4
gpt4 key购买 nike

我的 Google 登录功能/w Firebase 工作正常好几天,直到我退出后突然无法再次登录。它抛出这个异常:

04-28 23:28:17.639 1991-2393/com.google.android.gms.persistent W/GLSUser: [AppCertManager] IOException while requesting key: 
java.io.IOException: Invalid device key response.
at evk.a(:com.google.android.gms:274)
at evk.a(:com.google.android.gms:4238)
at evk.a(:com.google.android.gms:170)
at evj.a(:com.google.android.gms:63)
at evh.onTransact(:com.google.android.gms:58)
at android.os.Binder.transact(Binder.java:499)
at bxp.onTransact(:com.google.android.gms:35)
at android.os.Binder.execTransact(Binder.java:565)
04-28 23:28:17.640 1991-2393/com.google.android.gms.persistent W/GLSUser: [DeviceKeyStore] Cannot load key: Device key file not found.
04-28 23:28:17.890 2371-4189/com.google.android.gms E/Volley: [327] BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?key=AIzaSyAdxh0yBc4QUZ4-CjcOn472ieduZiShkwY
04-28 23:28:17.894 2371-22212/com.google.android.gms I/AuthChimeraService: Error description received from server: {
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid id_token in IdP response: eyJhbGciOiJSUzI1NiIsImtpZCI6ImNmYWVjZjI5MWFhM2M4YWZiMDg2ZGUxYmU3ZGJlNmM3NjMyODI3NDYifQ.eyJhenAiOiIyMzA4MzIzMTgwMjQtdmM5am1udmRydTVzMGYyaXNldnM2cm8zdTA3Nm1vYmouYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiIyMzA4MzIzMTgwMjQtbTZuMDFpampnYWI5cjdpYmdlNmE3ODQ0M2xvYzRlNW8uYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMTI5MTM1Mzg1MDg1MjY2MDU0MzciLCJlbWFpbCI6ImF2aWFtaXJzd2VAZ21haWwuY29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nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMTI5MTM1Mzg1MDg1MjY2MDU0MzciLCJlbWFpbCI6ImF2aWFtaXJzd2VAZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlzcyI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbSIsImlhdCI6MTQ5MzQ2OTg0MSwiZXhwIjoxNDkzNDczNDQxLCJuYW1lIjoiQWxpIEFtaWQiLCJwaWN0dXJlIjoiaHR0cHM6Ly9saDQuZ29vZ2xldXNlcmNvbnRlbnQuY29tLy1aZXVWdDZ6d1o4WS9BQUFBQUFBQUFBSS9BQUFBQUFBQUFBQS9BSGFsR2hxN2w5cW0xNlY4bDduZVNYdFdPMjlFSDVkLTVRL3M5Ni1jL3Bob3RvLmpwZyIsImdpdmVuX25hbWUiOiJBbGkiLCJmYW1pbHlfbmFtZSI6IkFtaWQiLCJsb2NhbGUiOiJlbiJ9.EyuUL2ONyko0VuwoRRxFcxCL1R6K3pYpDGx-poPa9jfj20jwALhg8aGArA_NZpg1qttTMagHrkfaaaNA2yvWZmy4nmvxoXKBHYRfjpatUstKd7GKcA28cJrONlM8ixEaI7Sie344jv53lLwbhpIb_OFjJWMVsQ3DoG9A-63nSliQC2LfAje2EcOaoDD7y3rDRKluRM18fmAijH6yKfR9PXNDKFOWDfWOC4XlXxuLvl18xUv8ExA-oZeHM8D_mF9p02ipEq_EyzQUwUzcVDjoJPeb_qDFjaHXZJ4KKD3pv30m8YP8LLQ6t_GXJwphwpqYVydGuIPHLsHz4Pmo-pP17w, error: Id_token failed validation."
}
}
04-28 23:28:17.897 22376-22376/com.appD/com.app.activity.SignInActivity: signInWithCredential:onComplete:false
04-28 23:28:17.897 22376-22376/com.appW/com.app.activity.SignInActivity: signInWithCredential
com.google.firebase.FirebaseException: An internal error has occurred. [ Invalid id_token in IdP response ]
at com.google.android.gms.internal.zzblv.zzce(Unknown Source)
at com.google.android.gms.internal.zzbls$zzj.zza(Unknown Source)
at com.google.android.gms.internal.zzbmd.zzcf(Unknown Source)
at com.google.android.gms.internal.zzbmd$zza.onFailure(Unknown Source)
at com.google.android.gms.internal.zzbly$zza.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:565)

我注销的代码:

//init google options
if(gso != null){
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
}
if(mGoogleApiClient != null){
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.enableAutoManage(getActivity(), this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}

//init sign out button and add an onclicklistener
signOut = (Button) rootView.findViewById(R.id.sign_out_button);
signOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Log out user from both FirebaseAuth and Google
mFirebaseAuth.signOut();
Auth.GoogleSignInApi.signOut(mGoogleApiClient);
startActivity(new Intent(getContext(), SignInActivity.class));
}
});

我登录的代码:

public class SignInActivity extends AppCompatActivity implements
GoogleApiClient.OnConnectionFailedListener, View.OnClickListener {

private static final String TAG = SignInActivity.class.getName();
private static final int RC_SIGN_IN = 9001;

private SignInButton mSignInButton;

private GoogleApiClient mGoogleApiClient;

// Firebase instance variables
private FirebaseAuth mFirebaseAuth;
private FirebaseUser mFirebaseUser;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);

// Assign fields
mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);

// Set click listeners
mSignInButton.setOnClickListener(this);

// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();

// Initialize FirebaseAuth
mFirebaseAuth = FirebaseAuth.getInstance();
mFirebaseUser = mFirebaseAuth.getCurrentUser();

}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
}
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
// An unresolvable error has occurred and Google APIs (including Sign-In) will not
// be available.
Log.d(TAG, "onConnectionFailed:" + connectionResult);
Toast.makeText(this, "Google Play Services error.", Toast.LENGTH_SHORT).show();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// Google Sign-In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
// Google Sign-In failed
Log.e(TAG, "Google Sign-In failed.");
}
}
}


private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mFirebaseAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "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.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(SignInActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
} else {
startActivity(new Intent(SignInActivity.this, MainActivity.class));
finish();
}
}
});
}

@Override
public void onDestroy() {
super.onDestroy();
mGoogleApiClient.stopAutoManage(this);
mGoogleApiClient.disconnect();
}

}

登录来自一个 Activity ,注销来自附加到另一 Activity 的 fragment (如果此信息在某种程度上相关)。

在方法 firebaseAuthWithGoogle(GoogleSignInAccount acct) (在 SignInActivity.java 中)中,身份验证失败。具体来说,mFirebaseAuth.signInWithCredential(credential) 失败。

我不知道为什么会发生这个错误,有人知道为什么吗?

最佳答案

Firebase 库已于昨天更新至 10.2.4: https://firebase.google.com/support/releases

我更新了 build.gradle 文件以使 Firebase 库版本与 Google Play 服务版本同步:

compile 'com.google.firebase:firebase-database:10.2.4'
compile 'com.google.firebase:firebase-core:10.2.4'
compile 'com.google.firebase:firebase-auth:10.2.4'
compile 'com.google.firebase:firebase-messaging:10.2.4'
compile 'com.google.android.gms:play-services-wearable:10.2.4'
compile 'com.google.android.gms:play-services-auth:10.2.4'

我不确定是否有必要,但我从模拟器中卸载了我的应用程序并重新部署了它。

我确实在日志记录中看到了“无效的设备 key 响应”错误,但在进行 build.gradle 更新之前看到的“IdP 响应中的无效 id_token”错误现已消失。我的用户已成功登录。

关于android - Google 登录(使用 Firebase)突然停止工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43696837/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com