amazon-web-services - 如何在 lambda 中读取 AWS cognito 自定义属性和登录用户
问题描述
我在 aws congnito 池中创建了一个自定义属性,现在添加 Post authentication lambda 和 lambda 内部想要读取“自定义属性”和登录用户名。
在 Node.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
。
推荐阅读
- debugging - 无法在 STM32CubeIDE 上的 AXI-SRAM 中为 STM32H753 设置断点
- extendscript - 如何在 After Effects 脚本中获取所有动画预设的列表
- c# - Inventor API 在测试环境下的行为与在开发环境下的行为不同
- laravel-5 - 如何使用 laravel 常量向用户隐藏侧边栏菜单?
- java - Flowable 将 bytearray 列加载为 BLOB
- async-await - 如何在 hylang 中编写像点(。)运算符这样的宏?
- sql - 有没有办法在 Oracle SQL 中将数字转换为带圆圈的数字?(1到①或20到⑳)
- concurrency - 使用并发调用从远程服务器检索数据的最佳方式是什么?
- javascript - 使用谷歌 cse 服务时出现错误:403 - ReactJS
- javascript - C#:错误的 DateTime 格式传递给前端