最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AWS Cognito - SerializationException (Start of structure or map found where not expected) - Stack Overflow

programmeradmin2浏览0评论

I have created a user in Cognito user pool, using the create user option as shown in the image, and want that user to set a new password on first Log In. For this I am using below given method, as given in the AWS documents Create User from AWS

cognitouserpleteNewPasswordChallenge()

Below is my code

//Start: setNewPasswordForAdmin
    setNewPasswordForAdmin(username: string, password: string) {

        //Start: Creating new user with username and pool data
        const adminUserdata = {
            Username: username,
            Pool: userpoolAdmin
        }
        const adminuser = new CognitoUser(adminUserdata);
        //End: Creating new user with username and pool data


        //create attributelist array which will contain all the attributes requried for signing in
        //these attributes are those attributes, which are selected while creating user pool on aws
        const attributeList : CognitoUserAttribute[] = [];

        //form a json object containing Name and Value of attribute used
        const usernameattribute = {
            Name:'username',
            Value: username
        }

        //Push list of attributes in the attributeList array
        attributeList.push(new CognitoUserAttribute(usernameattribute));
        console.log(attributeList);
        const that = this;

        adminuserpleteNewPasswordChallenge(password, attributeList ,{
            onFailure(err){

                console.log(err);
            },
            onSuccess(result){
                console.log(":::::::: Password change successfull ");

                that.router.navigate(['']);
            }
        });
    }
    //End: setNewPasswordForAdmin

After executing this I get an error saying,

{code: "SerializationException", name: "SerializationException", message: "Start of structure or map found where not expected."}

These are the attributes which I have selected in User Pool

List Of Attributes and permissions in user pool

Please help me to solve this.

I have created a user in Cognito user pool, using the create user option as shown in the image, and want that user to set a new password on first Log In. For this I am using below given method, as given in the AWS documents Create User from AWS

cognitouser.pleteNewPasswordChallenge()

Below is my code

//Start: setNewPasswordForAdmin
    setNewPasswordForAdmin(username: string, password: string) {

        //Start: Creating new user with username and pool data
        const adminUserdata = {
            Username: username,
            Pool: userpoolAdmin
        }
        const adminuser = new CognitoUser(adminUserdata);
        //End: Creating new user with username and pool data


        //create attributelist array which will contain all the attributes requried for signing in
        //these attributes are those attributes, which are selected while creating user pool on aws
        const attributeList : CognitoUserAttribute[] = [];

        //form a json object containing Name and Value of attribute used
        const usernameattribute = {
            Name:'username',
            Value: username
        }

        //Push list of attributes in the attributeList array
        attributeList.push(new CognitoUserAttribute(usernameattribute));
        console.log(attributeList);
        const that = this;

        adminuser.pleteNewPasswordChallenge(password, attributeList ,{
            onFailure(err){

                console.log(err);
            },
            onSuccess(result){
                console.log(":::::::: Password change successfull ");

                that.router.navigate(['']);
            }
        });
    }
    //End: setNewPasswordForAdmin

After executing this I get an error saying,

{code: "SerializationException", name: "SerializationException", message: "Start of structure or map found where not expected."}

These are the attributes which I have selected in User Pool

List Of Attributes and permissions in user pool

Please help me to solve this.

Share Improve this question edited Apr 20, 2018 at 5:56 Shardul Sane asked Apr 20, 2018 at 5:46 Shardul SaneShardul Sane 711 gold badge1 silver badge4 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 1

In my case it ended up being malformed data being sent to my resetPassword helper. The function was looking for three parameters (username, code, password):

export default function (username, code, password) {
    …
}

… and I was sending them as an object:

yield call(authResetPassword, {
    code: DOMPurify.sanitize(verificationCode),
    username: DOMPurify.sanitize(email),
    password: DOMPurify.sanitize(newPassword),
})

I just updated the helper and I was all set!

export default function ({ username, code, password }) {
    …
}

Just log your data in the setNewPasswordForAdmin function and I’ll bet you’ll find something awry there.

Edit: Due to OP's function parameter types, it wouldn't execute unless both params are String. They weren't in my case, so the issue was different. However, when one googles this error message, this page es up, so I leave my original answer below in case others have the same issue as I had:

I had (edit: almost) the same problem. As I understand now, this response is possible on various AWS APIs and it's not specific to Cognito, although I was working with a Cognito client app as well.

This response is sent when your request body contains variables of the wrong type, e.g. Boolean instead of string (or in my case, object instead of string).

However, Knowing this alone didn't help me. I was working with Vue.js, sending input element's values using CognitoUserPool.pleteNewPasswordChallenge and CognitoUserPool.signUp methods of amazon-cognito-identity-js. The request looked good in Chrome, the values seemed ok in Vue dev tools, and Amazon's error message was cryptic and undocumented.

The problem was that I sent the input element nodes themselves rather than the values of them: variableName instead of this.variableName.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论