Search code examples
javascriptoauth-2.0amazon-cognitoaws-amplify

Amplify Federated Sign In not returning Email for Facebook


I'm using AWS Amplify to add social signing. With google I'm getting the email of the user but it's missing in facebook.

This is my code:

  federatedSignIn(provider: any): void {
    switch (provider) {
      case 'facebook':
          console.log("Authenticating using Facebook");
          Auth.federatedSignIn({ provider: CognitoHostedUIIdentityProvider.Facebook });
          break;
      case 'google':
        console.log("Authenticating using Google");
        Auth.federatedSignIn({ provider: CognitoHostedUIIdentityProvider.Google });
        break;
    }
     
  }

This is what the "Pre sign-up" Lambda sees as an event.

{
    "version": "1",
    "region": "us-east-1",
    "userPoolId": "us-east-xxxxxx",
    "userName": "Facebook_123456",
    "callerContext": {
        "awsSdkVersion": "aws-sdk-unknown-unknown",
        "clientId": "123456abcd"
    },
    "triggerSource": "PreSignUp_ExternalProvider",
    "request": {
        "userAttributes": {
            "email_verified": "false",
            "cognito:email_alias": "",
            "phone_number_verified": "false",
            "cognito:phone_number_alias": ""
        },
        "validationData": {}
    },
    "response": {
        "autoConfirmUser": false,
        "autoVerifyEmail": false,
        "autoVerifyPhone": false
    }
}

Userpool settings enter image description here

enter image description here

Attribute mapping enter image description here


Solution

  • The issue was with <amplify-facebook-button> since it uses Identity Pool workflow instead of User Pool workflow. Creating a custom button with federatedSignIn()worked.

      <button  slot="federated-buttons" (click)=customSignIn()>Facebook</button>
    
      customSignIn(): void{
        Auth.federatedSignIn({provider: CognitoHostedUIIdentityProvider.Facebook });
      } 
    

    More info: https://github.com/aws-amplify/amplify-js/issues/8823