使用AWS Cognito进行react-native-google-signin

Luc*_*non 11 amazon-web-services react-native google-signin

我正在开发一个react-native应用程序,我想让我的用户能够使用google登录.但是,当我向google API发出请求时,它会返回WRONG SIGNIN Error: DEVELOPER_ERROR.

我正在使用AWS Cognito,并希望将Google登录与其集成.我看到一些问题说要生成我的"webClientId"的SHA-1蓝图,但所有这些都使用了firebase.在Cognito上,没有字段可以添加相应的SHA-1蓝图.

我的代码如下:

  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)}/> 
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助.

Mat*_*t D 1

这是配置不匹配。确保您的 android/app/google-services.json 正确。

您可能需要将 SHA 证书指纹添加到 Firebase 配置中。按照此帖子中的说明查找您的 SHA1 指纹: 密钥库证书的 SHA-1 指纹。然后,转到https://console.firebase.google.com/,选择您的应用程序,然后在“项目设置”(左上角的齿轮图标)->“您的应用程序”->“SHA 证书指纹”下添加 SHA1 值

如果您将配置对象中的 webClientId 传递给 GoogleSignin.configure(),请确保它是正确的。您可以从 Google 开发者控制台获取您的 webClientId。它们列在“OAuth 2.0 客户端 ID”下。

如果您在调试模式下运行应用程序并且不使用 webClientId 或者您确定它是正确的,则问题可能是签名(SHA-1 或 SHA-256)不匹配。您需要将以下内容添加到 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
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

那是从这里开始的。

我还在github 上找到了这个工作示例。