FB Login w/ React Native + AWS Cognito

血红的双手。 提交于 2019-12-25 12:53:29

问题


I am trying to use the react native FBDSK Wrapper library along with the AWS cognito javascript library (recently switched react native support over to the js library)

I am able to login with FB and retrieve the token but when I try to sign in using AWS cognito I do not see a succesful login in my AWS federated identity dashboard. I am wondering what am I doing wrong here?

index.js :

import React, { Component } from 'react';
import {
  Animated,
  Platform,
  StatusBar,
  StyleSheet,
  Text,
  View,
  Image,
  TouchableHighlight,
} from 'react-native';
var AWS = require('aws-sdk/dist/aws-sdk-react-native');
const FBSDK = require('react-native-fbsdk');
const {
  LoginButton,
  AccessToken
} = FBSDK;

var Login = React.createClass({
  render: function() {
    return (
      <View>
        <LoginButton
          publishPermissions={["publish_actions"]}
          onLoginFinished={
            (error, result) => {
              if (error) {
                alert("Login failed with error: " + result.error);
              } else if (result.isCancelled) {
                alert("Login was cancelled");
              } else {
                alert("Login was successful with permissions: " + result.grantedPermissions)
                 AccessToken.getCurrentAccessToken().then(
              (data) => {
                AWS.config.region = 'us-east-1';
                 AWS.config.credentials = new AWS.CognitoIdentityCredentials({
                IdentityPoolId: 'us-east-xxxxxxxxxxxxxxxxxxxxxx',
                Logins: {
                'graph.facebook.com': data.accessToken.toString()
                        }    
                         },
                         alert(data.accessToken.toString()) // I am able to see the access token so I know i am getting it succesfully
                         );
              }
            )


              }
            }
          }
          onLogoutFinished={() => alert("User logged out")}/>
      </View>
    );
  }
});

export default class App extends Component {
  render() {
    return (
      <View>
        <Text>Welcome to the Facebook SDK for React Native!</Text>
        <Login />
      </View>
    );
  }
}

回答1:


after you prepare the AWS.config.credentials =, you need to call AWS.config.credentials.get(()....)



来源:https://stackoverflow.com/questions/45384168/fb-login-w-react-native-aws-cognito

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!