Skip to content

adding all events for Cognito User Pool #175

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

Merged
merged 5 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.amazonaws.services.lambda.runtime.events;

import lombok.*;

import java.util.Map;

/**
* Represent the class for the Cognito User Pool Create Auth Challenge Lambda Trigger
*
* See <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-create-auth-challenge.html">Create Auth Challenge Lambda Trigger</a>
*
* @author jvdl <[email protected]>
*/
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class CognitoUserPoolCreateAuthChallengeEvent extends CognitoUserPoolEvent {

/**
* The request from the Amazon Cognito service.
*/
private Request request;

/**
* The response from your Lambda trigger.
*/
private Response response;

@Builder(setterPrefix = "with")
public CognitoUserPoolCreateAuthChallengeEvent(
String version,
String triggerSource,
String region,
String userPoolId,
String userName,
CallerContext callerContext,
Request request,
Response response) {
super(version, triggerSource, region, userPoolId, userName, callerContext);
this.request = request;
this.response = response;
}

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public static class Request extends CognitoUserPoolEvent.Request {
/**
* One or more key-value pairs that you can provide as custom input to the Lambda function that you specify for the create auth challenge trigger.
*/
private Map<String, String> clientMetadata;
/**
* The name of the new challenge.
*/
private String challengeName;
private ChallengeResult[] session;
/**
* This boolean is populated when PreventUserExistenceErrors is set to ENABLED for your User Pool client.
*/
private boolean userNotFound;

@Builder(setterPrefix = "with")
public Request(Map<String, String> userAttributes, Map<String, String> clientMetadata, String challengeName, ChallengeResult[] session, boolean userNotFound) {
super(userAttributes);
this.clientMetadata = clientMetadata;
this.session = session;
this.userNotFound = userNotFound;
this.challengeName = challengeName;
}
}

@AllArgsConstructor
@Builder(setterPrefix = "with")
@Data
@NoArgsConstructor
public static class ChallengeResult {
/**
* The challenge type. One of: "CUSTOM_CHALLENGE", "PASSWORD_VERIFIER", "SMS_MFA", "DEVICE_SRP_AUTH", "DEVICE_PASSWORD_VERIFIER", or "ADMIN_NO_SRP_AUTH".
*/
private String challengeName;
/**
* Set to true if the user successfully completed the challenge, or false otherwise.
*/
private boolean challengeResult;
/**
* Your name for the custom challenge. Used only if challengeName is CUSTOM_CHALLENGE.
*/
private String challengeMetadata;
}

@AllArgsConstructor
@Builder(setterPrefix = "with")
@Data
@NoArgsConstructor
public static class Response {
/**
* One or more key-value pairs for the client app to use in the challenge to be presented to the user.
* Contains the question that is presented to the user.
*/
private Map<String, String> publicChallengeParameters;
/**
* Contains the valid answers for the question in publicChallengeParameters
*/
private Map<String, String> privateChallengeParameters;
/**
* Your name for the custom challenge, if this is a custom challenge.
*/
private String challengeMetadata;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.amazonaws.services.lambda.runtime.events;

import lombok.*;

import java.util.Map;

/**
* Represent the class for the Cognito User Pool Custom Message Lambda Trigger
*
* See <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-message.html">Custom Message Lambda Trigger</a>
*
* @author jvdl <[email protected]>
*/
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class CognitoUserPoolCustomMessageEvent extends CognitoUserPoolEvent {
/**
* The request from the Amazon Cognito service.
*/
private Request request;

/**
* The response from your Lambda trigger.
*/
private Response response;

@Builder(setterPrefix = "with")
public CognitoUserPoolCustomMessageEvent(
String version,
String triggerSource,
String region,
String userPoolId,
String userName,
CallerContext callerContext,
Request request,
Response response) {
super(version, triggerSource, region, userPoolId, userName, callerContext);
this.request = request;
this.response = response;
}

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public static class Request extends CognitoUserPoolEvent.Request {
/**
* One or more key-value pairs that you can provide as custom input to the Lambda function that you specify for the custom message trigger.
*/
private Map<String, String> clientMetadata;
/**
* A string for you to use as the placeholder for the verification code in the custom message.
*/
private String codeParameter;
/**
* The username parameter. It is a required request parameter for the admin create user flow.
*/
private String usernameParameter;

@Builder(setterPrefix = "with")
public Request(Map<String, String> userAttributes, Map<String, String> clientMetadata, String codeParameter, String usernameParameter) {
super(userAttributes);
this.clientMetadata = clientMetadata;
this.codeParameter = codeParameter;
this.usernameParameter = usernameParameter;
}
}

@Data
@AllArgsConstructor
@Builder(setterPrefix = "with")
@NoArgsConstructor
public static class Response {
/**
* The custom SMS message to be sent to your users. Must include the codeParameter value received in the request.
*/
private String smsMessage;
/**
* The custom email message to be sent to your users. Must include the codeParameter value received in the request.
*/
private String emailMessage;
/**
* The subject line for the custom message.
*/
private String emailSubject;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.amazonaws.services.lambda.runtime.events;

import lombok.*;

import java.util.Map;

/**
* Represent the class for the Cognito User Pool Define Auth Challenge Lambda Trigger
*
* See <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-define-auth-challenge.html">Define Auth Challenge Lambda Trigger</a>
*
* @author jvdl <[email protected]>
*/
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class CognitoUserPoolDefineAuthChallengeEvent extends CognitoUserPoolEvent {

/**
* The request from the Amazon Cognito service.
*/
private Request request;

/**
* The response from your Lambda trigger.
*/
private Response response;

@Builder(setterPrefix = "with")
public CognitoUserPoolDefineAuthChallengeEvent(
String version,
String triggerSource,
String region,
String userPoolId,
String userName,
CallerContext callerContext,
Request request,
Response response) {
super(version, triggerSource, region, userPoolId, userName, callerContext);
this.request = request;
this.response = response;
}

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public static class Request extends CognitoUserPoolEvent.Request {
/**
* One or more key-value pairs that you can provide as custom input to the Lambda function that you specify for the define auth challenge trigger.
*/
private Map<String, String> clientMetadata;

private ChallengeResult[] session;

/**
* A Boolean that is populated when PreventUserExistenceErrors is set to ENABLED for your user pool client.
* A value of true means that the user id (user name, email address, etc.) did not match any existing users.
*/
private boolean userNotFound;

@Builder(setterPrefix = "with")
public Request(Map<String, String> userAttributes, Map<String, String> clientMetadata, ChallengeResult[] session, boolean userNotFound) {
super(userAttributes);
this.clientMetadata = clientMetadata;
this.session = session;
this.userNotFound = userNotFound;
}
}

@Data
@AllArgsConstructor
@Builder(setterPrefix = "with")
@NoArgsConstructor
public static class ChallengeResult {
/**
* The challenge type. One of: CUSTOM_CHALLENGE, SRP_A, PASSWORD_VERIFIER, SMS_MFA, DEVICE_SRP_AUTH, DEVICE_PASSWORD_VERIFIER, or ADMIN_NO_SRP_AUTH.
*/
private String challengeName;
/**
* Set to true if the user successfully completed the challenge, or false otherwise.
*/
private boolean challengeResult;
/**
* Your name for the custom challenge. Used only if challengeName is CUSTOM_CHALLENGE.
*/
private String challengeMetadata;
}

@Data
@AllArgsConstructor
@Builder(setterPrefix = "with")
@NoArgsConstructor
public static class Response {
/**
* Name of the next challenge, if you want to present a new challenge to your user.
*/
private String challengeName;

/**
* Set to true if you determine that the user has been sufficiently authenticated by completing the challenges, or false otherwise.
*/
private boolean issueTokens;

/**
* Set to true if you want to terminate the current authentication process, or false otherwise.
*/
private boolean failAuthentication;
}
}
Loading