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.
instead of calling
.refresh
call.get
like: