admin管理员组文章数量:1026989
I've implemented soft delete functionality with Cognito by marking a custom user status field as deleted. However, I need to catch login attempts and reject them in the Post authentication Lambda trigger as if they are unrecognized users. How do you do that in Python 3.9?
All I am getting is "Unrecognizable lambda output" and "InvalidLambdaResponseException" when I try to return an error.
I tried throwing an error or stuff along the lines of:
return {
"body": json.dumps({}, default=str),
"statusCode": 400,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Expose-Headers": "x-amzn-RequestId,x-amzn-ErrorType,x-amzn-ErrorMessage,Date",
# "Content-Length": "79",
"Content-Type": "application/x-amz-json-1.1",
# "Date": "Fri, 15 Nov 2024 19:14:19 GMT",
"X-Amzn-Errormessage": "Incorrect username or password.",
"X-Amzn-Errortype": "NotAuthorizedException:",
"X-Amzn-Requestid": context.aws_request_id
}
}
I've implemented soft delete functionality with Cognito by marking a custom user status field as deleted. However, I need to catch login attempts and reject them in the Post authentication Lambda trigger as if they are unrecognized users. How do you do that in Python 3.9?
All I am getting is "Unrecognizable lambda output" and "InvalidLambdaResponseException" when I try to return an error.
I tried throwing an error or stuff along the lines of:
return {
"body": json.dumps({}, default=str),
"statusCode": 400,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Expose-Headers": "x-amzn-RequestId,x-amzn-ErrorType,x-amzn-ErrorMessage,Date",
# "Content-Length": "79",
"Content-Type": "application/x-amz-json-1.1",
# "Date": "Fri, 15 Nov 2024 19:14:19 GMT",
"X-Amzn-Errormessage": "Incorrect username or password.",
"X-Amzn-Errortype": "NotAuthorizedException:",
"X-Amzn-Requestid": context.aws_request_id
}
}
Share
Improve this question
asked Nov 16, 2024 at 6:52
JustANoobJustANoob
871 gold badge2 silver badges12 bronze badges
1 Answer
Reset to default 1I think the feature you're actually looking for is enabling/disabling users. There's no need to build your own solution using Lambda triggers, this is available out of the box.
You can use the AdminDisableUser API to deactivate a specific user, which prevents them from logging in, which can effectively become a soft-delete. If you want, you can still add a custom attribute to make it more explicit.
If you want to undo the soft delete, you just use AdminEnableUser to reactivate them.
Since you're using Python, here are the corresponding boto3 docs:
- admin_disable_user
- admin_enable_user
I've implemented soft delete functionality with Cognito by marking a custom user status field as deleted. However, I need to catch login attempts and reject them in the Post authentication Lambda trigger as if they are unrecognized users. How do you do that in Python 3.9?
All I am getting is "Unrecognizable lambda output" and "InvalidLambdaResponseException" when I try to return an error.
I tried throwing an error or stuff along the lines of:
return {
"body": json.dumps({}, default=str),
"statusCode": 400,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Expose-Headers": "x-amzn-RequestId,x-amzn-ErrorType,x-amzn-ErrorMessage,Date",
# "Content-Length": "79",
"Content-Type": "application/x-amz-json-1.1",
# "Date": "Fri, 15 Nov 2024 19:14:19 GMT",
"X-Amzn-Errormessage": "Incorrect username or password.",
"X-Amzn-Errortype": "NotAuthorizedException:",
"X-Amzn-Requestid": context.aws_request_id
}
}
I've implemented soft delete functionality with Cognito by marking a custom user status field as deleted. However, I need to catch login attempts and reject them in the Post authentication Lambda trigger as if they are unrecognized users. How do you do that in Python 3.9?
All I am getting is "Unrecognizable lambda output" and "InvalidLambdaResponseException" when I try to return an error.
I tried throwing an error or stuff along the lines of:
return {
"body": json.dumps({}, default=str),
"statusCode": 400,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Expose-Headers": "x-amzn-RequestId,x-amzn-ErrorType,x-amzn-ErrorMessage,Date",
# "Content-Length": "79",
"Content-Type": "application/x-amz-json-1.1",
# "Date": "Fri, 15 Nov 2024 19:14:19 GMT",
"X-Amzn-Errormessage": "Incorrect username or password.",
"X-Amzn-Errortype": "NotAuthorizedException:",
"X-Amzn-Requestid": context.aws_request_id
}
}
Share
Improve this question
asked Nov 16, 2024 at 6:52
JustANoobJustANoob
871 gold badge2 silver badges12 bronze badges
1 Answer
Reset to default 1I think the feature you're actually looking for is enabling/disabling users. There's no need to build your own solution using Lambda triggers, this is available out of the box.
You can use the AdminDisableUser API to deactivate a specific user, which prevents them from logging in, which can effectively become a soft-delete. If you want, you can still add a custom attribute to make it more explicit.
If you want to undo the soft delete, you just use AdminEnableUser to reactivate them.
Since you're using Python, here are the corresponding boto3 docs:
- admin_disable_user
- admin_enable_user
本文标签: python 3xAWS Cognito Post authentication Lambda triggerreturn NotAuthorizedExceptionStack Overflow
版权声明:本文标题:python 3.x - AWS Cognito Post authentication Lambda trigger - return NotAuthorizedException - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745663912a2162060.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论