Search code examples
amazon-web-servicesauthenticationfacebook-graph-apiamazon-cognitofederated-identity

Cognito User Pools - Is it possible to create a custom sign up/in form for Facebook login?


I would like to use a Cognito User Pool for Facebook logins only, which may be possible using the built in login form, but I need to use my own.

Theoretically, when it comes to a custom form, it shouldn't be hard: after I receive a user object from FB, I bind the user and email attributes to the ones in my User Pool and I save it.

But what to do about the password field and future authentication? And here I have failed during my journey...

...
userPool.signUp('FoobarUser', '**password?**', attributeList, null, function(err, result){
...

While digging deeper into the docs, I tried to implement a Identity Pool (Federated Identities), managed to save user info in the form of datasets as well, but then I realised, querying these sets gonna be a huge pain if possible at all.

Maybe I'm failing to understand the concepts, I would be really thankful if someone could suggest a way to manage facebook logins in a nicely organised fashion using Cognito.


Solution

  • So here is what I understand from your query.

    Setup

    • Link Facebook to userpool
    • The app client allows only Facebook login, no other providers allowed (not even Userpool)
    • On login, you want Facebook user's info to be automatically populated in your Userpool
    • You don't want to use Cognito's builtin UI but use your own

    My 2 Cents

    This way, all Facebook users will be automatically created in your userpool. Of course, their names will be random like Facebook_123jkjdwj but all their details will be correctly populated from the token as per your attribute mapping. As a plus, all auto-created users from a particular provider are added to an auto-created group 'Userpoolid_providername' eg. us_east_1_xxxx_Facebook.