2017-07-29 106 views
0

我試圖使用與AWS cognito JavaScript庫一起反應本地FBDSK包裝庫(最近交換反應的原生支持了到JS庫)FB登錄W /陣營本地+ AWS Cognito

我能使用FB登錄並檢索令牌,但是當我嘗試使用AWS cognito登錄時,我在AWS聯合身份儀表板中看不到成功的登錄。我想知道我在這裏做錯了什麼?

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

您準備AWS.config.credentials =後,你需要調用AWS.config.credentials.get(()....)

+0

日Thnx奏效!我只是假設如果FB登錄成功,AWS會自動獲得憑據 – john