Amazon Cognito facebook login on Angular 2

772 views Asked by At

I am new to Amazon AWS cognito. can someone help to implement the facebook login on cognito. I have finished the steps give by cognito got logged in facebook and send that access token to cognito. Here is my code.

fblogin() {
    this.fb.login()

    .then((res: LoginResponse) => {
      console.log('cognito identitypole-->',CognitoUtil._IDENTITY_POOL_ID);
        AWS.config.credentials = new AWS.CognitoIdentityCredentials({
            IdentityPoolId: CognitoUtil._IDENTITY_POOL_ID,
            Logins: {
            'graph.facebook.com': res.authResponse.accessToken,                
            }                
        });            

    })
    .catch(this.handleError);
}

After this i dont have idea how to get registered in cognito using angular 2.

Any idea to implement facebook registration and login on cognito using angular 2

Thanks in advance

1

There are 1 answers

0
Kokuou On

Cognito have User Pool and Federated Identities. If you are using federated identities, it won't create a user in the User Pool

Federated Identities is like giving the user an access to your service without them having an account.

For Federated Sign in via AWS Amplify (client side)

Auth.federatedSignIn({
    domain,
    {
        token,
        identity_id, // Optional
        expires_at: expiresIn * 1000 + new Date().getTime() // the expiration timestamp
    },
    user
}).

Link: https://aws-amplify.github.io/docs/js/authentication

I suggest using AWS Amplify for client side AWS Cognito usage.

If you want users to have an account to your user pool when they sign up via Facebook or Google, I think Cognito's Hosted UI supports it but if you have your own UI, you will have a different approach. A question related to this: Using Cognito User Pools, without Cognito Federated Identities(identity pools)