python - 从 Cognito 获取 ClientID 的最佳方法
问题描述
在我Cognito
创建了多组用户池和客户端 ID 的设置中。每个用户池将包含一定数量的用户,其范围仅限于各自的 clientId。
现在我创建了 3 个不同的 lambda,并将这些 lambda 链接到 Api 网关。那些 lambda 和 API 端点路径看起来像signup
, confirm-signup
, forgot-password
, confirm-password
.
我的 python 准备好为客户端 ID 工作,并且存在一个用户池,这些 lambda 工作正常。我硬编码了我的clientid。例如
def lambda_handler(event, context):
for field in ["username", "email", "password", "name"]:
if not event.get(field):
return {"error": False, "success": True, 'message': f"{field} is not present", "data": None}
username = event['username']
email = event["email"]
password = event['password']
name = event["name"]
client = boto3.client('cognito-idp')
client.sign_up(
ClientId=CLIENT_ID,
SecretHash=get_secret_hash(username),
Username=username,
Password=password,
UserAttributes=[
{
'Name': "name",
'Value': name
},
{
'Name': "email",
'Value': email
}
],
ValidationData=[
{
'Name': "email",
'Value': email
},
{
'Name': "custom:username",
'Value': username
}
])
这个client-id指的是这个client-id所属的用户池。作为 boto3 客户端 ID 的一部分,必须调用sign-up
.
所以,现在我的问题是我有 2 个用户池和 2 个客户端 ID。
userpoolA-clientIdA
userpoolB-clinetIdB
所以,现在对于signup
API 调用,我正在传递 ["username", "email", "password", "name", "userpoolA"] 现在我的问题是如何进入clientIdA
lambdauserpoolA
以便我可以调用sign-up
mthod 并添加这个用户名到那个userpoolA
。
是的,这是必要的,我们需要以 poolA 用户不能也不会有资格访问 poolB 令牌或授权的方式来隔离用户。
我看到describe_user_pool但作为输入,它需要 UserPoolId 而不是 userpoolName。如果有人能提出最好的方法,将不胜感激。
解决方案
推荐阅读
- node.js - 如何在 Foreach 中同步运行 Mongoose Find
- html - 按元素抓取网页
- ios - 如何在 Xcode 中正确设置 UIButtons(图像)的约束?
- c - 这个基于指针的代码的答案是什么,为什么?
- c# - Windows IoT 上的多线程导致线程关闭
- java - BroadcastReceiver 未在 Android 8.1+ 上捕获呼叫事件
- reactjs - 具有循环连接的层次树
- java - 如何在我的单元测试中使用 Mockito 或任何 Mocking 框架来模拟 Guice 注入?
- firebase - 如何使用firebase云功能pubsub.schedule?
- javascript - 如何用正则表达式排除特定数字?