Cognito 用户池 - 是否可以为 Facebook 登录创建自定义注册/表单? [英] Cognito User Pools - Is it possible to create a custom sign up/in form for Facebook login?

本文介绍了Cognito 用户池 - 是否可以为 Facebook 登录创建自定义注册/表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想将 Cognito 用户池用于 Facebook 登录,这可能使用内置登录表单,但我需要使用自己的.

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.

理论上,当涉及到自定义表单时,应该不难:在我收到来自 FB 的用户对象后,我将用户和电子邮件属性绑定到我的用户池中的属性并保存.

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.

也许我没有理解这些概念,如果有人能提出一种使用 Cognito 以井井有条的方式管理 Facebook 登录的方法,我将非常感激.

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.

推荐答案

以下是我从您的查询中了解到的.

So here is what I understand from your query.

设置

  • 将 Facebook 链接到用户池
  • 应用客户端只允许 Facebook 登录,不允许其他提供商(甚至 Userpool)
  • 登录时,您希望 Facebook 用户的信息自动填充到您的用户池中
  • 您不想使用 Cognito 的内置 UI,而是想使用您自己的 UI

我的 2 美分

  • 在您的应用客户端中,只需选择 Facebook
  • 在您的用户界面中,有一个登录按钮.单击它应该重定向到您的用户池的authorization 端点

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

如果您想将自己的 UI 与多个提供程序一起使用,请在客户端中允许相同的操作,然后单击 UI 中的相应按钮(例如 Facebook),将用户重定向到授权端点,但在 URL 中附加 identity_provider

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

如果您想查看所有支持的身份提供商的名称,请使用 ListIdentityProviders API 调用

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

这样,所有 Facebook 用户都将自动在您的用户池中创建.当然,他们的名字会像 Facebook_123jkjdwj 一样随机,但他们的所有详细信息都将根据您的属性映射从令牌中正确填充.另外,来自特定提供商的所有自动创建的用户都被添加到自动创建的组Userpoolid_providername"中,例如.us_east_1_xxxx_Facebook.

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.

这篇关于Cognito 用户池 - 是否可以为 Facebook 登录创建自定义注册/表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆