当错误消息说userName和password不匹配时,如何通过Cognito对用户池中的用户进行身份验证? [英] How do you authenticate a user in a user pool via Cognito when error messages say userName and password don't match even though they do?

查看:146
本文介绍了当错误消息说userName和password不匹配时,如何通过Cognito对用户池中的用户进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我搞不清Cognito及其Javascript中的Beta用户池功能.由于可以在此处找到文档,因此我可以成功创建用户:

So I am messing around with Cognito and their Beta User Pools feature in Javascript. I am successfully creating users thanks to the documentation found here:

http://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-user-identity-pools-javascript-examples.html

当我尝试对用户进行身份验证时,尽管收到一条奇怪的错误消息,提示:

When I try and authenticate the users though I get a strange error message saying:

NotAuthorizedException:用户名或密码错误.

NotAuthorizedException: Incorrect username or password.

我不明白为什么会这样,因为我从字面上复制并粘贴了用于创建用户的userName和password的值,效果很好.

I don't understand why this is the case as I am literally copying and pasting the values for userName and password that I used to create the user, which is working fine.

下面是我的用于验证用户身份的代码:

Below is my code to authenticate the user:

//----- Setup
AWS.config.region = 'us-east-1'; // Region
    AWS.config.credentials = new AWS.CognitoIdentityCredentials({
        IdentityPoolId: 'myIdentityPoolId'
    });

    AWSCognito.config.region = 'us-east-1';

    AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({
        IdentityPoolId: 'myIdentityPoolId'
    });

    var poolData = { UserPoolId : 'myUserPoolId',
        ClientId : 'myClientId'
    };

//-----Authenticate a user
    alert('Authenticate a user with application');
    var authenticationData = {
        Username : 'markie17061993',
        Password : 'MeowWoof123456789!',
    };
    var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
    var poolData = { UserPoolId : 'myUserPoolId',
        ClientId : 'myClientId'
    };
    var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
    var userData = {
        Username : 'markie17061993',
        Pool : userPool
    };
    var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
    alert('hiss');
    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function (result) {
            console.log('access token + ' + result.getAccessToken().getJwtToken());
        },

        onFailure: function(err) {
            alert(err);
        },

    });

您在这里看到任何问题吗?我以为在这两个地方,我的UserName参数可能是一个不同的值或其他值:

Do you see anything wrong here? I thought perhaps my UserName parameter in these two places is meant to be a different value or something:

var authenticationData = {
        Username : 'markie17061993',
        Password : 'MeowWoof123456789!',
    };

var userData = {
        Username : 'markie17061993',
        Pool : userPool
    };

谢谢

推荐答案

如果您没有确认新注册的用户,则不会显示您的代码.如果不是,那将解释NotAuthorizedException.

Your code doesn't show if you are confirming the newly signed up user not. If you are not, that would explain the NotAuthorizedException. This example specifically is what you want to follow.

如果您不想确认正在通过您的应用注册的用户,则应使用

If you do not want to confirm the users being signed up from you app, you should use a PreSignUp trigger to autoConfirm your users.

这篇关于当错误消息说userName和password不匹配时,如何通过Cognito对用户池中的用户进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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