Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Denying a Sign-up request in Cognito User Pools

The description of a Cognito User Pools Pre Sign-up Lambda Trigger is:

This trigger is invoked when a user submits their information to sign up, allowing you to perform custom validation to accept or deny the sign up request.

I want to deny a sign-up request based on a certain condition in my Lambda. The trigger parameters (reproduced from the docs below) seem to only support auto-verification and auto-confirmation:

{
    "request": {
        "userAttributes": {
            "string": "string",
            ....
        },
        "validationData": {
            "string": "string",
            "string": "string",
             ....
        }
    },

    "response": {
        "autoConfirmUser": "boolean",
        "autoVerifyPhone": "boolean",
        "autoVerifyEmail": "boolean"
    }
}

How can I accept or deny a sign-up request based on the outcome of the Pre Sign-up Lambda Trigger?

like image 552
sfdz Avatar asked Jun 02 '18 21:06

sfdz


People also ask

What is the main difference between Cognito user pool and Cognito identity pool?

With a user pool, your app users can sign in through the user pool or federate through a third-party identity provider (IdP). Identity pools are for authorization (access control). You can use identity pools to create unique identities for users and give them access to other AWS services.

How do I set up authentication in Cognito?

Go to AWS Cognito service and click “Manage Identity Pools”. 2. Enter “Identity pool name”, expand the “Authentication providers” section and select “Cognito” tab. This is where the Cognito authentication provider will be registered with the Identity pool.

Does Cognito use to manage sign up and sign in functionality for mobile and web applications?

Amazon Cognito is designed for developers who want to add user management and sync functionality to their mobile and web apps. Developers can use Cognito Identity to add sign-up and sign-in to their apps and to enable their users to securely access their app's resources.


2 Answers

You can deny signup by throwing an exception, as shown here.

The exception message will be passed back to Cognito, and on to the client, in the form of a validation error with the message PreSignUp failed with error {exceptionMessage}..

like image 50
Grejdi Avatar answered Oct 12 '22 16:10

Grejdi


You can return a empty dict from the lambda to deny sign up request. Similarly you return the event value itself to accept the sign up request.

def lambda_handler(event, context):
    if denySignUp:
        return {}
    else:
        return event
like image 42
Manoj Acharya Avatar answered Oct 12 '22 15:10

Manoj Acharya