gpt4 book ai didi

authentication - 我可以以编程方式创建 AWS Cognito 用户登录吗?

转载 作者:行者123 更新时间:2023-12-04 12:07:43 25 4
gpt4 key购买 nike

我希望我的应用程序允许拥有 Facebook、Google、Amazon...等帐户的用户能够登录我的应用程序。这通过 AWS Cognito 运行良好。

但是,如果用户没有任何这些登录名,应用程序是否可以通过编程方式创建用户登录名?

  • 用户将提供 id 和密码,应用程序会将信息发送给身份验证提供程序以创建新的登录名/帐户。
  • 我不需要实现自己的身份验证机制,也不需要担心密码的存储方式等。

  • 根据我的研究,我认为现有的身份验证提供程序甚至其他服务(例如 OpenID)都无法做到这一点。

    如果我不想实现自己的登录存储和身份验证,您还有其他选择吗?它不一定需要与 AWS Cognito 集成。

    最佳答案

    我对你的问题有点困惑。如果你问:

    Can I create new usernames and passwords on Facebook / Google programatically?



    那么答案是否定的。你必须在他们的网站上注册 Facebook/Google。如果你问:

    Can I create a new user with a username and password that only exists in Cognito?



    那么答案是肯定的。为此,这取决于您是在浏览器中还是在服务器上创建用户。在浏览器中,使用 Cognito Javascript API .在服务器上,使用 Cognito Admin Server APIs .

    下面是一些示例代码,用于在 Node JS 的服务器上创建一个新用户(用你自己的 token 替换我的字符串,尤其是那些带有 @ 符号的字符串):
      let params = {
    UserPoolId: "@cognito_pool_id@",
    Username: "jhancock",
    DesiredDeliveryMediums: ["EMAIL"],
    ForceAliasCreation: false,
    MessageAction: "SUPPRESS",
    TemporaryPassword: "somePassword",
    UserAttributes: [
    { Name: "given_name", Value: "John"},
    { Name: "family_name", Value: "Hancock"},
    { Name: "name", Value: "John Hancock"},
    { Name: "email", Value: "john@gmail.com"},
    { Name: "phone_number", Value: "+15125551212"}
    ],
    };
    console.log("Sending params to cognito: " + JSON.stringify(params));
    let cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider({region: "us-east-1"});
    cognitoIdentityServiceProvider.adminCreateUser(params, function(error, data) {
    if (error) {
    console.log("Error adding user to cognito: " + JSON.stringify(error), error.stack);
    } else {
    console.log("Received back from cognito: " + JSON.stringify(data));
    }
    }

    一旦你开始工作,你可能想看到这篇关于如何 change the temporary password into a real one 的帖子。 .

    关于authentication - 我可以以编程方式创建 AWS Cognito 用户登录吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25292096/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com