Using Facebook Login with AWS Cognito User Pool

I am implementing Facebook authentication for an Angular2 app that already uses an AWS Cognito user pool.

Using ngx-facebook ( https://github.com/zyra/ngx-facebook ) I was able to authenticate myself with Facebook and the Cognito Identity Pool:

    loginWithFacebook(): void {
        AWS.config.update({region:AWS_CONFIG.REGION});

        this.fb.login()
          .then((response: LoginResponse) => {
            console.log(response.authResponse.accessToken);

            AWS.config.credentials = new AWS.CognitoIdentityCredentials({
              IdentityPoolId: AWS_CONFIG.IDENTITY_POOL_ID,
              Logins: {
                'graph.facebook.com': response.authResponse.accessToken
              }
            });

            AWS.config.credentials.refresh((error) => {
              if (error) {
                  console.error(error);
              } else {
                  console.log('Successfully logged in');
              }
            });
          })
          .catch((error: any) => console.error(error));
      }

      

But now: how do I integrate Facebook users with an already existing user pool?

There is functionality for logging in and registering with the user pool, and the best solution would obviously be to use the existing functionality for Facebook users as well.

The backend has no server (Lambdas / API Gateway) and uses an authorizer connected to an existing user pool.

+6


source to share


3 answers


First of all, as mentioned, there was no integration with social ID providers in the Cognito UserPool . However, you can create your own directory of social account users (Facebook, Google, etc.) from Federated Identities using a database of your choice. Take a look at this discussion.



Secondly, now you don't need to do what is described in the first part of this post. A few days ago, Amazon announced federation support through Facebook, Google, and LoginWithAmazon for custom pools . "This will create a user in the user pool when the user logs on using federation. You can also get the attributes from the identity provider using the attribute mapping feature." - This is also mentioned here .

+2


source


Unfortunately, Cognito UserPool does not have integration with social identity providers like Facebook, Twitter, Google. This is only supported in Cognito Federated Identities. We are happy to accept this as a feature request.



+1


source


instead of calling .refresh

call.get

as:

AWS.config.credentials.get((error) => ...

      

-2


source







All Articles