aws-samples / amazon-cognito-passwordless-auth

Passwordless authentication with Amazon Cognito: FIDO2 (WebAuthn, support for Passkeys), Magic Link, SMS OTP Step Up
Apache License 2.0
367 stars 63 forks source link

Reword customization procedure #136

Closed tinti closed 8 months ago

tinti commented 8 months ago

Issue #, if available: n/a.

Description of changes: Make clear that your custom logic is appended at the end of the Lambda functions. Then the original logic is swapped by yours.

There is no need to create a new real Lambda function or clone the library logic at the example.

ottokruse commented 8 months ago

Hi mate, thanks for this.

Question about:

There is no need to create a Lambda function construct in this case

What do you mean exactly, because I think you do need to create your own Lambda function construct. Or do you just provide the entry in the functionProps as override to point to your code? If so, we should probably mention that, agree?

tinti commented 8 months ago

Hi there,

I am not native English speaker. When I read swap in I thought I would need to create a new Lambda function on CDK like:

      new lambda.NodeJsFunction(
        this,
        `NewFunction`,
        {
          entry: path.join('../new_function'),
          index: 'index.ts',
          runtime: lambda.Runtime.NODEJS_18_X,
          memorySize: 128
        }
      );

And add all the logic on it (the library's and mine) then swap the createAuthChallenge function.

But as far as understood this is not needed in some cases. Because the library is able to allow one to append custom code at the end of its function. This code can change some behaviors.

ottokruse commented 8 months ago

When I read swap in I thought I would need to create a new Lambda function on CDK like:

You do need to define your own Lambda function like in the code snippet you just pasted. However in the code for that Lambda function, you can use the library code.

Or do you have another way?

But as far as understood this is not needed in some cases. Because the library is able to allow one to append custom code at the end of its function. This code can change some behaviors.

Can you clarify this?

Maybe share a (more) complete code snippet of how you do it? Thanks!

ottokruse commented 8 months ago

Any update @tinti ?

tinti commented 8 months ago

Hi @ottokruse,

What I meant is that you don't really need to create a lambda function in the use case example. You just need to create the code for the lambda function.

When I first read and tried to implement I was writing a whole function (cdk for function creating and function code). But later I notice that it was just a matter of using the library to point to an file with my code. And plus, my code can perform some changes in the library (where it supports).

From my perspective I think it would be nice to make it clear. So at the example in the README.md file you:

tinti commented 8 months ago

Sorry for the late reply.

Another explanation: at line 60 I am not creating a new instance of a lambda function I am just appending my core at the end of an existing function from the library. That is what was not so clear for me.

https://github.com/aws-samples/amazon-cognito-passwordless-auth/blob/5a6743f4245ce3a90a70ac47639d08a32182e0f0/CUSTOMIZE-AUTH.md?plain=1#L58,L65

ottokruse commented 8 months ago

Thanks I now understand your point and you are totally right! You change the entry to point to your code, and then your code will actually be used.