我正在尝试使用 AWS Cognito 创建自定义身份验证流程,以便我可以通过电子邮件而不是通过 Cognito 触发器发送 MFA 代码。我正在使用 initiateAuth() 方法来执行此操作,根据文档,这是正确的;
https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_InitiateAuth.html https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#initiateAuth -财产
我的有效负载似乎有效,但当我尝试使用用户登录时,出现错误“t.getauthparameters 不是函数”
我浏览了其他一些 stackoverflow 帖子,但没有任何帮助
有什么想法出了什么问题吗?
这是我的代码片段如下:
const payload = {
AuthFlow: 'CUSTOM_AUTH',
ClientId: 'my client id',
AuthParameters: {
USERNAME: $('input[name=username]').val(),
PASSWORD: $('input[name=password]').val(),
CHALLENGE_NAME: 'SRP_A'
}
};
cognitoUser.initiateAuth(payload, {
onSuccess: function(result) {
// User authentication was successful
},
onFailure: function(err) {
// User authentication was not successful
},
customChallenge: function(challengeParameters) {
// User authentication depends on challenge response
var verificationCode = prompt('Please input OTP code' ,'');
cognitoUser.sendCustomChallengeAnswer(verificationCode, …Run Code Online (Sandbox Code Playgroud) javascript frontend amazon-web-services amazon-cognito amazon-cognito-triggers
我们可以在 AWS Cognito 中为应用程序客户端(客户端凭证)触发预令牌生成 lambda 吗?
但是,当我使用callback(null, event)lambda函数时,它实际上将永远不会返回,并且最终会导致错误
{代码:“ UnexpectedLambdaException”,名称:“ UnexpectedLambdaException”,消息:“ arn:aws:lambda:us-east-2:642684845958:function:proj-dev-confirm-1OP5DB3KK5WTA失败,并在调用Lambda函数时出现错误套接字超时。” }
我在这里找到了一个类似的链接,说要使用context.done()。
切换后,它可以正常工作。
有什么不同?
exports.confirm = (event, context, callback) => {
event.response.autoConfirmUser = true;
context.done(null, event);
//callback(null, event); does not work
}
Run Code Online (Sandbox Code Playgroud) amazon-web-services node.js amazon-cognito aws-lambda amazon-cognito-triggers
我已经在 中创建了一个用户池Cognito。
我想做的是,当新用户尝试使用 UI 注册时,他会收到验证码。用户输入代码后,Post confirmation必须触发 lambda,并且必须将这个新创建的用户直接添加到名为 的组中users。
我找到了admin_add_user_to_group客户端并编写了以下代码并将其部署为 lambda:
import boto3
import hmac
import hashlib
import base64
USER_POOL_ID = ''
CLIENT_ID = ''
CLIENT_SECRET = ''
def lambda_handler(event, context):
client = boto3.client('cognito-idp')
try:
username = event['username']
response = client.admin_add_user_to_group(
UserPoolId=USER_POOL_ID,
Username=username,
GroupName='users'
)
except client.exceptions.InvalidParameterException:
return {"error": True, "success": False, "message": "Username doesnt exists"}
except client.exceptions.ResourceNotFoundException:
return {"error": True, "success": False, "message": "Invalid Verification code"}
except client.exceptions.NotAuthorizedException:
return {"error": True, "success": …Run Code Online (Sandbox Code Playgroud) amazon-web-services python-3.x amazon-cognito aws-lambda amazon-cognito-triggers