Ashu
Ashu

Reputation: 95

AWS Cognito: Create User Issue

Our requirement is to create a user in AWS Cognito, using mobile and password confirmation and then update the user attributes like name, city, email etc on registration process. To achieve this firstly calling 'Auth.confirmSignUp' to get the OTP for mobile number confirmation and then calling 'Auth.signIn' to update the attributes via 'Auth.updateUserAttributes' but the issue is 'Auth.signIn' is failing and returning status code as 400 with the below response.

Response:

{"__type":"InvalidParameterException","message":"Custom auth lambda trigger is not configured for the user pool."}

Request:

{"AuthFlow":"CUSTOM_AUTH","ClientId":"XXXXXXX","AuthParameters":{"USERNAME":"447XXXXXXXX"},"ClientMetadata":{}}

But if I call Auth.signIn on login page it is working fine but observed that "AuthFlow":"CUSTOM_AUTH" changes to "AuthFlow":"USER_SRP_AUTH".

Not able to understand what am missing during the entire process or any other config changes to be done to fix the issue.

We are using aws-amplify library in React for front end. Code snippet as below.

awsUtils.js ==========

export const signUp = async (userName, password, attributes = {}) => {
    try {
        const response = await Auth.signUp({
            username: userName,
            password,
            attributes: {
                phone_number: userName,
                'custom:role': USER_ROLES.CUSTOMER,
                ...attributes
            }
        });
        return { success: true, response };
    } catch (error) {
        return { success: false, error };
    }
};

export const confirmSignUp = async (userName, otp) => {
    try {
        const response = await Auth.confirmSignUp(userName, otp);
        return { success: true, response };
    } catch (error) {
        return { success: false, error };
    }
};

export const signIn = async (userName, password) => {
    try {
        const response = await Auth.signIn(userName, password);
        return { success: true, response };
    } catch (error) {
        return { success: false, error };
    }
};

In react component first step we show only phone number and password: ===========

const { success } = await signUp(userName, password);
if(success){ //if successfull then show OPT field on client side.
    const { success } = await confirmSignUp(userName, otp);
    if( success ){ //If OPT is confirmed on congnito then a call is made to singin.
         const { success } = await signIn(userName, password); // But breaking here ...
    }
}

Have taken reference from https://docs.amplify.aws/lib/auth/emailpassword/q/platform/js/#sign-in.

AWS configuration:

For the first time on the component mount (load) we calling below aws configuration function.

export const initializeSDK = async () => {
    const {
        regin,
        redirectSignIn,
        redirectSignOut,
        domain,
        identityPoolId,
        poolId,
        webClientId,
        scope
    } = await getEnvConfig();

    const oauth = {
        domain,
        scope: scope?.split(','),
        redirectSignIn,
        redirectSignOut,
        responseType: 'token'
    };
    Amplify.configure({
        oauth: oauth,
        aws_project_region: regin,
        aws_cognito_identity_pool_id: identityPoolId,
        aws_user_pools_id: poolId,
        aws_user_pools_web_client_id: webClientId,
        domain: domain,
        scope: scope,
        redirectSignIn: redirectSignIn,
        redirectSignOut: redirectSignOut,
        responseType: 'CODE',
        AdvancedSecurityDataCollectionFlag: 'true',
        aws_cognito_region: regin,
        socialResponseType: 'token'
    });
};

Upvotes: 0

Views: 1442

Answers (1)

Ninad Gaikwad
Ninad Gaikwad

Reputation: 4480

The issue is obvious. Your request has CUSTOM_AUTH for AuthFlow. Custom Auth requires lambda. If you want regular username password authentication then go for USER_PASSWORD_AUTH

Upvotes: 0

Related Questions