Skip to content

Is CognitoEventResponse necessary? #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Buratti opened this issue May 29, 2024 · 2 comments
Closed

Is CognitoEventResponse necessary? #56

Buratti opened this issue May 29, 2024 · 2 comments
Assignees
Labels
good first issue Good for newcomers kind/support Adopter support requests.

Comments

@Buratti
Copy link
Contributor

Buratti commented May 29, 2024

Let me start by saying that I am bit rusty on the topic since I haven't touched our custom auth lambda in almost two years, and that this isn't really an issue but more of an idea I'd like to discuss.

I was looking at the CognitoEvents and I was wondering if the distinction between the request and response event is actually necessary.

Since Cognito already provides an empty response object in the input event, we could remove the Response event.

This would have the added (debatable?) benefit of editing the inner response objects in place. I don't know if you like the idea, since this isn't exactly the most "Swift" way to go, but it would allow to write code which is very similar to the examples provided in the AWS doc, making the adoption easier I would guess. Those example usually edit the event.response in-place and then return the input event as the Lambda output.

POC:

enum CognitoEvent {
    case defineAuthChallenge(DefineAuthChallenge)
}

struct DefineAuthChallenge: Codable {
    let version: String
    let region: String
    let userPoolId: String
    let userName: String
    let callerContext: [String: String]
    let triggerSource: String
    let request: Request
    var response: Response
    
    struct Request: Codable {
        let userAttributes: [String: String]
        let session: [Challange]
        let userNotFound: Bool
        
        struct Challange: Codable {
            let challengeName: String
            let challengeResult: Bool
            let challengeMetadata: String
        }
    }
    
    final class Response: Codable {
        var challengeName: String?
        var issueTokens: Bool?
        var failAuthentication: Bool?
    }
}

switch event {
case .defineAuthChallenge(let defineAuthChallenge):
    defineAuthChallenge.response.challengeName = "MY_CUSTOM_2FA"
default:
    throw UnsupportedEvent()
}
@sebsto
Copy link
Contributor

sebsto commented Jun 10, 2024

@Buratti hello Alessio, can you please comment on the PR #57 ? Thank you

@sebsto
Copy link
Contributor

sebsto commented Jun 12, 2024

Closing in favour of the discussion on #57

@sebsto sebsto closed this as completed Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers kind/support Adopter support requests.
Projects
None yet
Development

No branches or pull requests

2 participants