I'm working on a react-native / Expo app using Amplify with Cognito for Authentication and Authorization. I have configured Federated Sign On for Facebook and Google+ using the amplify CLI.
I am not using the hosted UI, I have created my own login interface with the respective buttons.
Here is the code for the Facebook Sign-In button:
import { FontAwesome } from '@expo/vector-icons'
import { Auth } from 'aws-amplify'
import * as Facebook from 'expo-facebook'
import React, { Fragment } from 'react'
import { Alert } from 'react-native'
import core from '../../core'
export default () => {
const handleFBSignIn = async () => {
try {
await Facebook.initializeAsync({
appId: "##################"
})
const { type, token, expires } = await Facebook.logInWithReadPermissionsAsync()
if (type === 'success') {
const { id, email, name } = await (await fetch(`https://graph.facebook.com/me?access_token=${token}&fields=id,name,email`)).json()
await Auth.federatedSignIn('facebook', { token, expires_at: expires }, { name, email })
}
} catch (ex) {
await Alert.alert('Facebook Sign in Failed', ex.message, ['Ok'])
}
}
return (
<core.components.VisionButton
title={<Fragment><FontAwesome name='facebook' size={16} color='#fff' /> Facebook</Fragment>}
color='facebook'
style={{ margin: 6 }}
onPress={handleFBSignIn}
/>
)
}
The call to Auth.federatedSignIn(...) succeeds and I get back a FederatedUser
Hub also receives an auth event for signIn
As far as the app is considered, there is now an authenticated user. However, whenever I try to call any AWS resources that require authentication I get No Current User.
I have also noticed that, while the Facebook login is shown in the Cognito Identity Pool, no user is created in the Cognito User Pool.
How do I get a CognitoUser from a Federated Sign In?