簡體   English   中英

AWS通過google登錄React Native時出錯

[英]Error while AWS login through google in react native

我正在通過Google進行AWS登錄,正在登錄,並且已打印警報。 但是問題是我登錄后進入catch錯誤。我已打印警報,如代碼中所示,登錄后我得到了13條警報。 Alert.alert(“ 13”); 有App.js類,其中Google按鈕附加了登錄Google。 我正在編寫auth類的代碼,該過程在通過Google進行AWS登錄之間進行。 我在github中關注了此鏈接。 https://github.com/patw0929/react-native-amplify-cognito-example

export const loginGoogle = () => {
  return new Promise(async(resolve, reject) => {
    const user = await GoogleSignin.signIn().catch(error => {
      // console.log('WRONG SIGNIN', error);
      console.log('getOpenIdToken', getOpenIdToken);
      Alert.alert("13");
    });
    if (user) {
      const credential = await googleGetCredential();
      if (credential) {
        const result = await getOpenIdToken('accounts.google.com',
          credential.identityId, credential.idToken);
        resolve(result);
        Alert.alert("8");
        return;
      }
      reject('Authentication failed');
      console.log('failed');
      Alert.alert("9");
      return;
    }
    return;
  });
};

export const getOpenIdToken = async(provider, identityId, token) => {
  const payload = {
    IdentityId: identityId,
    Logins: {
      [provider]: token,
    },
  };
  Alert.alert("10");
  try {
    const rsp = await fetch(COGNITO_IDENTITY_API, {
      method: 'POST',
      headers: new Headers({
        'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken',
        'Content-Type': 'application/x-amz-json-1.1',
        random: new Date().valueOf(),
        'cache-control': 'no-cache',
      }),
      body: JSON.stringify(payload),
    });
    if (!rsp.ok) {
      logout();
    } else {
      const json = await rsp.json();
      return json.Token;
    }
  } catch (e) {
    console.log('Error of getOpenIdToken: ', e);
  }
};

const googleConfigure = () => {
  GoogleSignin.hasPlayServices({
      autoResolve: true
    })
    .then(() =>
      GoogleSignin.configure({
        iosClientId: GOOGLE_SIGNIN_IOS_CLIENT_ID,
        webClientId: GOOGLE_SIGNIN_WEBCLIENT_ID,
      })
    );
};

export const init = () => {
  googleConfigure();
};

我想獲取令牌以在警報中打印。 任何幫助將不勝感激。

在這里輸入圖像描述 Bram,在這個問題上,很多信息都丟失了。 至少,錯誤消息必須存在

  1. 首先,您正在使用的庫較舊,請嘗試使用AWS Amplify,該庫的功能要優越得多,並且已經過安全性和錯誤測試。
  2. 在AWS聯合登錄中,可以通過兩種方式完成登錄,一種使用Cognito用戶池,也可以使用Cognito身份池。 我希望您正在使用Cognito身份池。
  3. 請在“編輯身份池”->“身份驗證提供者”->“ Google+”中添加Google客戶端ID。
  4. 將您要在Google Developer帳戶中訪問的域列入白名單。

完整的文檔在這里https://itnext.io/google-sign-in-using-aws-amplify-and-amazon-cognito-69cc3bf219ad

https://aws.amazon.com/blogs/mobile/amplify-framework-adds-authentication-features-and-enhancements-for-ios-and-android-mobile-sdks/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM