Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 651
Edmond Tamas Avatar asked Oct 30 '17 15:10

Edmond Tamas


People also ask

How do I customize my AWS Cognito login page?

Sign in to the Amazon Cognito console . In the navigation pane, choose User Pools, and choose the user pool you want to edit. Choose the App integration tab. To customize UI settings for all app clients, locate Hosted UI customization and select Edit.

How do I set up Facebook as a federated identity provider in an Amazon Cognito user pool?

From the navigation bar choose Add Product and choose Set up for the Facebook Login product. From the navigation bar choose Facebook Login and then Settings. Enter the path to the /oauth2/idpresponse endpoint for your user pool domain into Valid OAuth Redirect URIs. Choose Save changes.

Does Cognito provide SSO?

Your user pool acts as a service provider (SP) on behalf of your application. Amazon Cognito supports SP-initiated single sign-on (SSO) as described in section 5.1.

What is the difference between user pool and identity pool?

With a user pool, your app users can sign in through the user pool or federate through a third-party identity provider (IdP). Identity pools are for authorization (access control). You can use identity pools to create unique identities for users and give them access to other AWS services.


1 Answers

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

  • In your app client, just select Facebook
  • In your UI, have a login button. On clicking it should redirect to your userpool's authorization endpoint

    https://your_domain.auth.us-east-1.amazoncognito.com/oauth2/authorize?redirect_uri=https://www.example.com&response_type=token&client_id=your_appclient_id

  • If you want to use your own UI with multiple providers, allow the same in Client and on clicking the appropriate button in your UI (say Facebook), redirect users to the authorize endpoint but append the identity_provider in the URL

    https://your_domain.auth.us-east-1.amazoncognito.com/oauth2/authorize?redirect_uri=https://www.example.com&response_type=token&client_id=your_appclient_id&identity_provider=Facebook

  • If you want to see the names of all supported identity providers, use ListIdentityProviders API call

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.

like image 162
agent420 Avatar answered Oct 29 '22 14:10

agent420