Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native-google-signin with AWS Cognito

I'm working on a react-native application and I want to give my users the ability to login with google. But, when I make the request to the google API, it returns WRONG SIGNIN Error: DEVELOPER_ERROR.

I am using AWS Cognito and want to integrate the Google login with it. I saw some questions that said to generate a SHA-1 blueprint of my "webClientId", but all of them use firebase. On Cognito, there's no field to add the respective SHA-1 blueprint.

My code is the follow:

  componentWillMount() {
        GoogleSignin.configure({
          webClientId: googleConfig.clientId
        });
    }

...

  googleSignIn() {
      GoogleSignin.signIn()
      .then((user) => {
        console.log(user);
        this.setState({user: user});
      })
      .catch((err) => {
        console.log('WRONG SIGNIN', err);
      })
      .done();
  }

...

<GoogleSigninButton
              style={{ height: 48 }}
              size={GoogleSigninButton.Size.Standard}
              color={GoogleSigninButton.Color.Light}
              onPress={this.googleSignIn.bind(this)}/> 

Thanks in advance for the help.

like image 806
Lucas Bordignon Avatar asked Feb 16 '18 02:02

Lucas Bordignon


1 Answers

This is configuration mismatch. Make sure that your android/app/google-services.json is correct.

You may need to add your SHA certificate fingerprint to your Firebase config. Find your SHA1 fingerprint by following the instructions on this post: SHA-1 fingerprint of keystore certificate. Then, go to https://console.firebase.google.com/, select your app, and add the SHA1 value under Project Settings (gear icon in the upper left) -> Your Apps -> SHA certificate fingerprints

If you're passing webClientId in configuration object to GoogleSignin.configure() make sure it's correct. You can get your webClientId from Google Developer Console. They're listed under "OAuth 2.0 client IDs".

If you're running your app in debug mode and not using webClientId or you're sure it's correct the problem might be signature (SHA-1 or SHA-256) mismatch. You need to add the following to android/app/build.gradle:

signingConfigs {
    debug {
        if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
    release {
        if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
}

That's from here.

I also found this working example on github.

like image 151
Matt D Avatar answered Nov 17 '22 00:11

Matt D