7

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 have managed to authenticate myself using Facebook and a 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 the Facebook users with the already existing user pool?

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

The backend is serverless (Lambdas/API Gateway) and uses an Authorizer connected to the existing user pool.

Victor Kim
  • 1,647
  • 2
  • 16
  • 33
Karl Eriksson
  • 205
  • 4
  • 12

3 Answers3

3

First of all, as mentioned, Cognito UserPool did not have integrations with social Identity providers. However, you could implement a directory of social account users(facebook, google, etc.) from Federated Identities by yourself, using a database of your choice. Look into this discussion.

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

Victor Kim
  • 1,647
  • 2
  • 16
  • 33
  • 4
    I've been trying to get this new functionality to work for days with no success. I can login with my linked federated identity and get AWS credentials for that user, but I have never seen the user created in the user pool or the attributes being captured anywhere. Is there any tutorial on this stuff? I've never found one that goes through the entire process. – JasonPerr Oct 12 '17 at 15:58
1

Unfortunately Cognito UserPool does not have integrations with social Identity providers like Facebook, Twitter, Google. That's only supported in Cognito Federated Identities. We are happy to take this as a feature request.

patanjal
  • 645
  • 4
  • 4
-2

instead of calling .refresh call .get

like:

AWS.config.credentials.get((error) => ...
UXDart
  • 2,500
  • 14
  • 12