BigJump
BigJump

Reputation: 16419

How to disable AWS Cognito User Pool account created via Identity Provider?

Any Cognito User Pool gurus out there? I've been using Cognito for a while now but this one has me a bit stumped.

So as I see it I have two options:

Am I missing something obvious?

Thanks in advance!

Upvotes: 1

Views: 3600

Answers (2)

BigJump
BigJump

Reputation: 16419

The simplest solution in the end for us was a Pre Token Generation Trigger in Cognito like this:

exports.handler = async (event) => {

  if(event.triggerSource==="TokenGeneration_HostedAuth") {

     //check db/api etc to see if we have a valid registration stored for user
     if(!hasCompletedRegistration) {

       //throw auth exception which we can catch on the frontend to inform user
       throw new Error("REGISTRATION_NOT_COMPLETE")
     }
  }

  return event

};

For username/password sign ins the TriggerSource will be TokenGeneration_Authentication

For federated/social sign ins the TriggerSource will be TokenGeneration_HostedAuth

Upvotes: 2

Leon Africa
Leon Africa

Reputation: 609

I would say PostConfirmation Lambda trigger is a good approach - however instead use adminDisableProviderForUser to disable the user from signing in with the specified external (SAML or social) identity provider

adminDisableProviderForUser

You can later call adminLinkProviderForUser to link the existing user account in the user pool to the external identity provider.

adminLinkProviderForUser

An alternative solution is to prevent the user from signing in if they have not fully completed the registration process via a Pre Authentication Lambda Trigger checking for a unique identifier with respect to your completed registration process

Upvotes: 1

Related Questions