我的 AWS Lambda 函数可以与经过 Cognito 身份验证的用户一起正常工作。
我现在正在尝试让未经身份验证的 Cognito 用户继续使用。
我在后端找不到任何方法来确定调用 Lambda 函数的当前用户是否已通过身份验证。
我掌握的关于用户的识别信息是他们的 Cognito IdentityId,但我如何使用它来找出未经身份验证的信息?
我在 Lambda 中使用 Python boto3.6。
最佳答案
检查这个 http://boto3.readthedocs.io/en/latest/reference/services/cognito-identity.html#CognitoIdentity.Client.describe_identity
如果它是授权用户,您将获得登录名。从未使用过,但我认为这是了解的方式
编辑: 来自 OP:是的,这是正确的 - 重要的是返回值中缺少 key “登录”意味着用户未经身份验证。
res = client2.describe_identity(
IdentityId=context.identity.cognito_identity_id
)
if ('Logins' not in res.keys()):
return True
else:
return False
关于python-3.x - AWS Cognito - 如何确定用户是否未经身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45580144/