Search code examples
amazon-cognitoamazon-cognito-triggers

AWS Cognito use custom auth flow with external identity provider


is it possible to use AWS Cognito that has a custom authentication flow enabled, while also using an external identity provider like Facebook or Google? I've tried this with Facebook and the Cognito Hosted UI, but my DefineAuthChallenge-trigger was not hit.


Solution

  • I contacted AWS Support and they pointed me to the Cognito documentation here where a note says that

    The Amazon Cognito hosted sign-in web page does not support the custom authentication flow.

    As an alternative, this solution was proposed:

    Alternatively, if you would like to use custom authentication flow with an external identity provider, you will have to write your own custom login flow using one of Cognito's SDKs and use Facebook as a way of login.

    My idea is that you can probably do this by defining a custom challenge, that asks, which identity provider you want to use, as the first, initial challenge. If Cognito is chosen, the user needs to provide their SRP-stuff or username and password, if that is enabled. If Facebook is chosen for example, you would probably need to send an auth challenge to the client saying that you want a token or code from them, which can only be gotten, if the client shows the website with the Facebook login. The challenge response to the server would then be the gotten auth token from Facebook or code or some other answer that the server can then use to authenticate the user within Cognito, where the Facebook app is connected and is registered as an external identity provider

    This is my idea of how I would go about to do this, but I haven't actually implemented this. I hope this helps someone trying to do this though.