【问题标题】:How do I send a user pool user a custom email when invoking forgot_password调用 forgot_password 时如何向用户池用户发送自定义电子邮件
【发布时间】:2019-12-08 05:48:40
【问题描述】:

AWS Cognito IDP(身份提供商)是 AWS 提供的一项服务,用于通过用户池管理您的服务的用户。 Cognito 提供了多种 API,并且可以通过 boto3(AWS 的 Python 包装器)以编程方式使用 Cognito。

forgot_password 方法在用户忘记密码时使用:

   cog.forgot_password(ClientId=USER_POOL_CLIENT_ID, Username=req["username"])

这会向用户发送一封电子邮件,其中包含用户可用于更改密码的六位数代码。

问题是,我希望电子邮件包含自定义内容以及六位数代码。我确信这一定是可能的,必须有一种方法来获取模板化内容并使用该模板化内容向用户发送一封包含自定义内容的电子邮件,其中还包含六位数代码。

有谁知道,在使用 boto3 为 AWS Cognito IDP 调用 forgot_password 时,我如何发送包含六位数代码的自定义电子邮件?

谢谢!

【问题讨论】:

    标签: amazon-web-services amazon-cognito


    【解决方案1】:

    Amazon Cognito 在发送电子邮件或电话验证消息或多重身份验证 (MFA) 代码之前调用自定义触发器,让您可以动态自定义消息。

    您需要创建一个 lambda 函数并使用 CustomMessage_ForgotPassword 作为 triggerSource。例如:

    if(event.userPoolId === "theSpecialUserPool") {
        // Identify why was this function invoked
        if(event.triggerSource === "CustomMessage_ForgotPassword") {
            // Ensure that your message contains event.request.codeParameter. This is the placeholder for code that will be sent
            event.response.emailSubject = "Forgot Password";
            event.response.emailMessage = "Your customized text here" + event.request.codeParameter + " and your verification code";
        }
        // Create custom message for other events
    }
    

    然后通过执行以下操作将此 lambda 函数与您的认知池集成:

    AWS 控制台 -> Cognito -> 池 -> 常规设置 -> 触发器 -> 自定义消息。

    因此,每次用户调用忘记密码时,您的池都会触发上述 lambda,而不是默认的忘记密码 AWS cognito lambda。

    参考

    1. https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-message.html

    【讨论】:

      猜你喜欢
      • 2020-04-16
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      • 2011-06-30
      • 1970-01-01
      • 1970-01-01
      • 2019-04-21
      • 2011-01-02
      相关资源
      最近更新 更多