Amazon Cognito JS SDK

PabloBarríaUrenda

我正在尝试使用其JavaScript SDK来了解Cognito身份验证。我有以下代码(由React应用程序中的表单触发):

import {
    CognitoUserPool,
    AuthenticationDetails,
    CognitoUser
} from "amazon-cognito-identity-js";

const poolData = {
    UserPoolId: MY_POOL_ID,
    ClientId: APP_CLIENT_ID
};

export function cognitoLogin(credentials, callback) {
    const authenticationDetails = new AuthenticationDetails(credentials);

    const userPool = new CognitoUserPool(poolData);
    const cognitoUser = new CognitoUser({
        Username: credentials.username,
        Pool: userPool
    });

    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function(response) {
            console.log("SUCCESS!");
            console.log(response);
        },
        onFailure: function(error) {
            console.log("FAILURE!");
            console.log(error);
        }
    });
}

我生成的客户端应用程序没有任何秘密。我生成了一个用户,并使用自定义域UI来登录该用户并进行确认。但是,当我尝试通过SDK登录时,

{
    code: "NotAuthorizedException",
    message: "Incorrect username or password.",
    name: "NotAuthorizedException"
}

错误。我可能会缺少什么?

伊沃·格洛夫

credentials对象必须包含键,Username并且Password-请注意,它们的首字母大写,但您的似乎全部为小写。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如果我已经有了aws-sdk(javascript),是否需要amazon-cognito-identity-js?

Amazon Cognito和Android SDK的问题NotAuthorizedException:无效的登录令牌

如何在Aurelia中使用Amazon Cognito Identity SDK?

如何使用Amazon Cognito sdk实施* Remember me *选项?

Cognito使用哪个AWS JS SDK包?

AWS Amplify和amazon-cognito-identity-js之间的区别?

使用Amazon Cognito Identity js阻止多个登录会话

可以使用iOS SDK在Amazon Cognito中更改用户名吗?

Amazon Cognito登录

Blazor WebAssembly + Amazon Cognito

使用Facebook和Google+提供者身份验证的Amazon Cognito iOS SDK V2的问题

使用 CognitoUser 仅验证“代码”(npm:amazon-cognito-identity-js)

错误:用户未在Node.js中通过身份验证的Amazon Cognito

Angular + Amazon-Cognito-identity-js,为什么我会出错:未定义全局

Amazon-cognito-identity-js,获取 callback.newPasswordRequired 不是函数错误

Amazon Cognito JS Authflow不会发送密码进行用户迁移

Amazon Cognito中的用户角色

AWS Cognito无法进行身份验证:空白答案-JS SDK

Amazon SES PHPMail或SDK

Amazon Cognito区域与AWS Console区域

AWS:Amazon Cognito与STS和SAML

Amazon Cognito连接找不到IdentityPool

Amazon Cognito多租户最佳方法

Amazon Cognito托管的UI无法内嵌?

从网页以Amazon Cognito注册Facebook访问令牌

在iOS中使用Amazon Cognito调用GetID

用于登录Amazon的AWS Cognito导致NotAuthorizedException

iOS Amazon Cognito 登录错误 InvalidParameterException

找不到Amazon Cognito身份池