如何在 Serverless 中设置 Cognito 用户池登录选项?

问题描述 投票:0回答:1

我想将 Cognito 用户池的登录选项设置为同时包含用户名和电子邮件。因此,当用户注册时,他们将被要求输入电子邮件、用户名和密码。

我似乎可以通过AWS控制台进行设置,但无法通过无服务器或云形成找出设置(因为我认为无服务器在幕后使用此设置?)

我有当前的无服务器配置,它创建一个包含用户名和密码的登录主机 UI 注册表单:

CognitoUserPool:
      Type: 'AWS::Cognito::UserPool'
      Properties:
        UserPoolName: 'MyAppUserPool${self:custom.stage}'
        UsernameConfiguration:
          CaseSensitive: false
        AutoVerifiedAttributes:
          - 'email'
        Policies:
          PasswordPolicy:
            MinimumLength: 8
            RequireUppercase: true
            RequireLowercase: true
            RequireNumbers: true
            RequireSymbols: true
            
    CognitoUserPoolClient:
      Type: 'AWS::Cognito::UserPoolClient'
      Properties:
        ClientName: 'MyAppUserPoolClient${self:custom.stage}'
        GenerateSecret: true
        UserPoolId:
          Ref: 'CognitoUserPool'
        CallbackURLs:
          - 'http://localhost:3000/api/auth/callback/cognito'
        SupportedIdentityProviders:
          - 'COGNITO'
        AllowedOAuthFlowsUserPoolClient: true
        AllowedOAuthFlows: 
          - 'code'
          - 'implicit'
        AllowedOAuthScopes:
          - 'email'
          - 'openid'
          - 'profile'
    
    CognitoUserPoolDomain:
       Type: 'AWS::Cognito::UserPoolDomain'
       Properties:
        Domain: 'my-app-${self:custom.stage}'
        UserPoolId: 
          Ref: 'CognitoUserPool'

我可以设置以下内容,但这使它只有电子邮件和密码用于注册(删除用户名:

UsernameAttributes: 
  - 'email'

我试图在此处云形成文档中找到配置选项,但似乎看不到任何允许配置用户池登录选项的内容。

任何有关如何使用用户名和电子邮件托管 UI 的帮助将不胜感激,谢谢。

amazon-web-services oauth-2.0 aws-cloudformation amazon-cognito serverless
1个回答
0
投票
我认为您需要将电子邮件添加为架构上的必需属性,而不是尝试将两者都添加到 UsernameAttributes 中。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpool.html#cfn-cognito-userpool-schema

此外,请记住,模式在创建后是不可变的,因此在开始在用户池中存储数据之前,您需要确保它具有您想要的一切。

© www.soinside.com 2019 - 2024. All rights reserved.