So I've been messing with this for a couple of days now and I cannot figure out why it doesn't work. I am really hoping someone can help me.
I am trying to authenticate a user with Google sign in using Firebase. So following their guide here I have set up Google sign in to get an OAuth token and then use that to authenticate with Firebase. So I set up Google as they describe in their guide here but that is as far as I got. The OAuth token I get from Google is always null and the result code is Status{statusCode=DEVELOPER_ERROR, resolution=null}.
So far, my activity looks like this:
public static final int RC_GOOGLE_LOGIN = 1;
private GoogleApiClient mGoogleApiClient;
final Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Firebase.setAndroidContext(this);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(this.getResources().getString(R.string.server_client_id))
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
SignInButton signInButton = (SignInButton) findViewById(R.id.googlebtn);
signInButton.setSize(SignInButton.SIZE_WIDE);
signInButton.setScopes(gso.getScopeArray());
signInButton.setOnClickListener(this);
}
@Override
public void onClick (View v) {
switch (v.getId()) {
case R.id.googlebtn:
signIn();
break;
}
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_GOOGLE_LOGIN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_GOOGLE_LOGIN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
String idToken = acct.getIdToken();
}
}
I have been googling this for a while and think I've tried everything that is already suggested. Of course I have done everything in the guides, added dependencies ('com.google.android.gms:play-services-auth:8.4.0') and created the necessary clients in the developer console.
I have also checked (multiple times) that the server client ID I am using is the right one from the Developer console, and that it matches my package name in both my gradle file and Manifest file. I have added the google-services.json file to my /app directory and even regenerated it to make sure it matches. I have also checked that the SHA1 key is correct and it still gives the same error.
If I remove the requestIdToken from the Google sign in options it works though, but that doesn't help me as I then cannot sign in with Firebase. Can someone tell me what I need to do to make it work?
Have you set your R.string.server_client_id
?
- Open the Credentials page in the API Console.
- The Web application type client ID is your backend server's OAuth 2.0 client ID.
https://developers.google.com/identity/sign-in/android/start-integrating#get_your_backend_servers_oauth_20_client_id
After the SHA-1 this is the next stumbling point that I've seen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With