capless / warrant

Python library for using AWS Cognito. With support for SRP.
Apache License 2.0
468 stars 192 forks source link

Change Password ParamValidationError #95

Open toriancrane opened 6 years ago

toriancrane commented 6 years ago

I am building a web application using Python/Flask and I'm trying to get Cognito to work using Warrant. I am running into two issues currently.

First Issue: Below is the code I have when trying to authenticate a user who is logging in for the first time.

@app.route('/', methods=['GET', 'POST'])
def homePage():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']

        u = Cognito(pool_id, client_id, username)
        try:
            u.authenticate(password)
            return redirect('/folders')
        except ForceChangePasswordException:
            u.change_password(password, 'Test@12345')
            return redirect('/folders')
    else:
        return render_template('index.html')

When I click "Submit" on the web page, I get this Traceback and error information.

My understanding is that 'USERNAME': auth_params['USERNAME'], is probably returning 'NONE' instead of the username provided by the user, but I am not sure why that is happening.

Note: pool_id and client_id information purposefully omitted here but it is included in my actual code.

Second Issue: As you can see in the code above, I have to hard code the new password as one of the arguments for u.change_password() method. I am not sure how to get it to work where the user would be providing their new password information because the app just throws an error before anything else can be done. How do I get the web page to request the new password information from the user?

To reiterate, once the ForceChangePasswordException is reached, how do I get a "Please change your password" page to pop up instead of the error Traceback?