从Cognito触发器发送消息 [英] Sending message from Cognito triggers

查看:0
本文介绍了从Cognito触发器发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望限制用户从Cognito托管的UI登录。我可以看到有一些触发器,我们可以在其中附加lambda,但每当我更改lambda内部的事件对象时,我没有得到我的自定义消息User exceeded limits,而是得到了unrecognizable lambda output错误。

有人能在这方面帮我吗?或者有其他方法可以实现这一功能吗?

现在,我得到了这个

使用此代码:

exports.handler = (event, context, callback) => {
    if (true) {
        var error = new Error("Cannot signin because your signin count is 5");
        // Return error to Amazon Cognito
        callback(error, event);
    }
    // Return to Amazon Cognito
    callback(null, event);
};

但是,我不想要前缀PreAuthentication failed with error,我只想显示我的消息。

感谢任何帮助。

推荐答案

目前,无法阻止Cognito添加前缀,因为该表单是托管的Web用户界面。

如果这是一个硬性要求,解决方法是创建您自己的登录表单并使用aws-Cogito-sdk

在下面的代码中调用CogitoUser.authateUser之后,预身份验证触发器将触发Lambda函数,您将需要处理错误并对其进行解析以删除不需要的前缀。

希望这能有所帮助

aws Examples: Using the JavaScript SDK

var authenticationData = {
    Username : 'username',
    Password : 'password',
};
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
var poolData = { UserPoolId : 'us-east-1_TcoKGbf7n',
    ClientId : '4pe2usejqcdmhi0a25jp4b5sh3'
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
    Username : 'username',
    Pool : userPool
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: function (result) {
        var accessToken = result.getAccessToken().getJwtToken();

        /* Use the idToken for Logins Map when Federating User Pools with identity pools or when passing through an Authorization Header to an API Gateway Authorizer*/
        var idToken = result.idToken.jwtToken;
    },

    //Your message from the Lambda will return here, you will need to parse the err to remove the unwanted prefix*
    onFailure: function(err) {

        alert(err);
    },

});

这篇关于从Cognito触发器发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆