使用React Native + AWS Cognito的FB登录 [英] FB Login w/ React Native + AWS Cognito

查看:114
本文介绍了使用React Native + AWS Cognito的FB登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将react native FBDSK Wrapper库与AWS Cognito javascript库一起使用(最近将React native支持切换到js库)

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)

我是能够使用FB登录并检索令牌,但是当我尝试使用AWS Cognito登录时,在我的AWS联合身份信息仪表板中看不到成功的登录。我想知道我在做什么错吗?

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>
    );
  }
}


推荐答案

之后准备 AWS.config.credentials = 时,您需要调用 AWS.config.credentials.get(()....)

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

这篇关于使用React Native + AWS Cognito的FB登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆