AWS扩大Facebook登录名,联合身份

时间:2019-03-10 07:27:36

标签: amazon-web-services react-native facebook-graph-api expo aws-amplify

我正在使用Cognito用户池在React Native Expo应用程序中管理用户注册和登录。我也想用Facebook登录。该文档说,如果您已经在使用Cognito用户池,则无需使用Auth.federatedSignIn(),因此我不确定还需要使用什么以及如何使用?

https://aws-amplify.github.io/docs/js/authentication#federated-identities-social-sign-in

到目前为止,这是我的代码

loginFB = async (params) => {
        try {
            const {
                type,
                token,
                expires,
                permissions,
                declinedPermissions,
            } = await Facebook.logInWithReadPermissionsAsync('414271525994061', {
                permissions: ['public_profile,email'], behavior: 'native'
            });

            console.log('type:', type);
            console.log('token:', token);

            if (type === 'success') {
        // Get the user's name using Facebook's Graph API

                const response = await fetch(`https://graph.facebook.com/me?access_token=${token}`);
        // Alert.alert('Logged in!', `Hi ${(await response.json()).name}!`);

        const user = {
          name: response.name,
          email: response.email
        };

        const date = new Date();

        const expires_at = expires * 1000 + date.getTime();

        Auth.federatedSignIn('facebook', { token, expires_at }, user)
                .then(credentials => {
                    console.log(credentials);
                });

            } else {
                // type === 'cancel'
            }
        } catch ({ message }) {
            alert(`Facebook Login Error: ${message}`);
        }
    }

0 个答案:

没有答案