代码之家  ›  专栏  ›  技术社区  ›  Pablo Barría Urenda

亚马逊认知JS SDK

  •  1
  • Pablo Barría Urenda  · 技术社区  · 8 年前

    我正在尝试使用他们的JavaScript SDK来理解认知认证。我有以下代码(由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);
            }
        });
    }
    

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

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

    错误。我能错过什么?

    1 回复  |  直到 8 年前
        1
  •  1
  •   IVO GELOV    8 年前

    这个 credentials 对象必须包含键 Username Password -注意,它们的第一个字母大写,但您的似乎都是小写。