'Android Firebase Google auth only working when run from single computer
I'll try to clarify the title a bit more. I have implemented Google signin with firebase for my Android application. When I tried it on my iMac everything is working fine. I can select the account and login with that account.
The problem occurs when I try to build/run the Android application from another laptop. When I try to login I can still select an account, but upon selecting an account it does not proceed to login and the signin activity reappears. The logs don't show anything.
Here's how I login/logout, but I don't think this is the problem.
public class AuthController {
private AuthListener authListener;
static final int RC_SIGN_IN = 9001;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
public AuthController(){
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(AUTHCONTROLLER_TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(AUTHCONTROLLER_TAG, "onAuthStateChanged:signed_out");
}
authListener.onUserAuthenticated(user);
}
};
}
public void startAuthStateListener() {
mAuth.addAuthStateListener(mAuthListener);
}
public void stopAuthStateListener() {
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
public void firebaseAuthWithGoogle(GoogleSignInAccount acct, Activity activity) {
Log.d(AUTHCONTROLLER_TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(AUTHCONTROLLER_TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state authListener will be notified and logic to handle the
// signed in user can be handled in the authListener.
if (!task.isSuccessful()) {
Log.w(AUTHCONTROLLER_TAG, "signInWithCredential", task.getException());
}
}
});
}
public void signOut() {
mAuth.signOut();
}
void setAuthListener(AuthListener authListener) {
this.authListener = authListener;
}
interface AuthListener {
void onUserAuthenticated(FirebaseUser user);
}
I'm guessing it has something to do with the configurations of the keys and/or google-services.json. But i'm not sure how to proceed. The json files are identical on both computers.
Any help would be appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
