首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我尝试在AWS-cognito CL中使用用户设置登录时,为什么会收到未知错误?

当我尝试在AWS-cognito CL中使用用户设置登录时,为什么会收到未知错误?
EN

Stack Overflow用户
提问于 2019-10-11 06:09:06
回答 1查看 163关注 0票数 0

我正在尝试为我的应用程序创建登录页面。它是纯html、css和JS。我已经在AWS-cognito cl中创建了用户,但当我尝试使用凭据时,它无法登录,我得到的唯一信息是这是一个未知错误。

我试着在这个问题上找到一些东西,但什么也没有出现。我找到的许多答案都涉及到newPasswordRequired函数或正在使用的sdk的版本。我已经反复检查了我的用户池id和客户端id。

代码语言:javascript
复制
function signInButton() {

    var authenticationData = {
        Username : document.getElementById("inputUsername").value,
        Password : document.getElementById("inputPassword").value,
    };

    var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);

    var poolData = {
        UserPoolId : _config.cognito.userPoolId, 
        ClientId : _config.cognito.clientId,
    };

    var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

    var userData = {
        Username : document.getElementById("inputUsername").value,
        Pool : userPool,
    };

    var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);

    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function (result) {
            resolve(result.getAccessToken().getJwtToken());
        },
        onFailure: function (err) {
            console.log("Error from cognito promise: ", err);

        },
        newPasswordRequired: function (userAttributes) {
            delete userAttributes.email_verified;
            cognitoUser.completeNewPasswordChallenge(newPassword, userAttributes, this);
        }
    });

    };

我希望它明显做的是登录并转到指定的页面,我知道错误函数确实有效,因为在此之前,我实际上会获得信息。我不想或需要这个MFA,我只想用一个用户登录并通过管理员设置的MFA,这可能是我在cl中设置的错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-14 05:24:30

在这里做的明智的事情是看一下我是如何处理newPassword函数的。我没有给它一种方式或机会来更改密码,因为我的应用程序要求用户登录,这是管理员创建的,这要求用户在登录时更改密码。

代码语言:javascript
复制
        newPasswordRequired: function (userAttributes,requiredAttributes) {
            delete userAttributes.email_verified;
            let attributesData = {name: authenticationData.Username}
            var newPassword = prompt('Enter new password ' ,'');
            cognitoUser.confirmPassword( newPassword, this);
            cognitoUser.completeNewPasswordChallenge(newPassword, attributesData, this);
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58331740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档