如何读取 AWS cognito 自定义属性并在 lambda 中登录用户



我已经在aws congnito池中创建了一个自定义属性,现在添加身份验证后lambda,并且在lambda内部想要读取"自定义属性"并登录用户名。

在节点内部.js lambda:

  var email=event.request.userAttributes.email;
  var refNumber=event.request.userAttributes.ref_number; //custom attribute
  var loginid=event.request.userAttributes.username;//loggedin id in cognito

我能够正确获取电子邮件ID,但是登录用户名和自定义属性都未定义。

自定义属性命名custom:xxx其中xxx是自定义属性名称:

{
    "version": "1",
    ...,
    "userName": "...",
    "triggerSource": "PostAuthentication_Authentication",
    "request": {
        "userAttributes": {
            "sub": "...",
            "cognito:user_status": "CONFIRMED",
            ...
            "locale": "en",
            ...
            "custom:xxx": "yyy"
        },
        "newDeviceUsed": true
    },
    "response": {}
}

所以为了你的ref_number,应该是event.request.userAttributes['custom:ref_number']的。

用户名只是event.userName

最新更新