Skip to content

Commit 22b9925

Browse files
jeromevdlcarlzogh
andauthored
Add all events for Cognito User Pool (aws#175)
Co-authored-by: Carl Zogheib <[email protected]>
1 parent 2af9acf commit 22b9925

11 files changed

+1089
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5+
* the License. A copy of the License is located at
6+
*
7+
* http://aws.amazon.com/apache2.0
8+
*
9+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
package com.amazonaws.services.lambda.runtime.events;
14+
15+
import lombok.*;
16+
17+
import java.util.Map;
18+
19+
/**
20+
* Represent the class for the Cognito User Pool Create Auth Challenge Lambda Trigger
21+
*
22+
* See <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-create-auth-challenge.html">Create Auth Challenge Lambda Trigger</a>
23+
*
24+
* @author jvdl <[email protected]>
25+
*/
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
@NoArgsConstructor
29+
public class CognitoUserPoolCreateAuthChallengeEvent extends CognitoUserPoolEvent {
30+
31+
/**
32+
* The request from the Amazon Cognito service.
33+
*/
34+
private Request request;
35+
36+
/**
37+
* The response from your Lambda trigger.
38+
*/
39+
private Response response;
40+
41+
@Builder(setterPrefix = "with")
42+
public CognitoUserPoolCreateAuthChallengeEvent(
43+
String version,
44+
String triggerSource,
45+
String region,
46+
String userPoolId,
47+
String userName,
48+
CallerContext callerContext,
49+
Request request,
50+
Response response) {
51+
super(version, triggerSource, region, userPoolId, userName, callerContext);
52+
this.request = request;
53+
this.response = response;
54+
}
55+
56+
@Data
57+
@EqualsAndHashCode(callSuper = true)
58+
@NoArgsConstructor
59+
public static class Request extends CognitoUserPoolEvent.Request {
60+
/**
61+
* 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.
62+
*/
63+
private Map<String, String> clientMetadata;
64+
/**
65+
* The name of the new challenge.
66+
*/
67+
private String challengeName;
68+
private ChallengeResult[] session;
69+
/**
70+
* This boolean is populated when PreventUserExistenceErrors is set to ENABLED for your User Pool client.
71+
*/
72+
private boolean userNotFound;
73+
74+
@Builder(setterPrefix = "with")
75+
public Request(Map<String, String> userAttributes, Map<String, String> clientMetadata, String challengeName, ChallengeResult[] session, boolean userNotFound) {
76+
super(userAttributes);
77+
this.clientMetadata = clientMetadata;
78+
this.session = session;
79+
this.userNotFound = userNotFound;
80+
this.challengeName = challengeName;
81+
}
82+
}
83+
84+
@AllArgsConstructor
85+
@Builder(setterPrefix = "with")
86+
@Data
87+
@NoArgsConstructor
88+
public static class ChallengeResult {
89+
/**
90+
* The challenge type. One of: "CUSTOM_CHALLENGE", "PASSWORD_VERIFIER", "SMS_MFA", "DEVICE_SRP_AUTH", "DEVICE_PASSWORD_VERIFIER", or "ADMIN_NO_SRP_AUTH".
91+
*/
92+
private String challengeName;
93+
/**
94+
* Set to true if the user successfully completed the challenge, or false otherwise.
95+
*/
96+
private boolean challengeResult;
97+
/**
98+
* Your name for the custom challenge. Used only if challengeName is CUSTOM_CHALLENGE.
99+
*/
100+
private String challengeMetadata;
101+
}
102+
103+
@AllArgsConstructor
104+
@Builder(setterPrefix = "with")
105+
@Data
106+
@NoArgsConstructor
107+
public static class Response {
108+
/**
109+
* One or more key-value pairs for the client app to use in the challenge to be presented to the user.
110+
* Contains the question that is presented to the user.
111+
*/
112+
private Map<String, String> publicChallengeParameters;
113+
/**
114+
* Contains the valid answers for the question in publicChallengeParameters
115+
*/
116+
private Map<String, String> privateChallengeParameters;
117+
/**
118+
* Your name for the custom challenge, if this is a custom challenge.
119+
*/
120+
private String challengeMetadata;
121+
}
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5+
* the License. A copy of the License is located at
6+
*
7+
* http://aws.amazon.com/apache2.0
8+
*
9+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
package com.amazonaws.services.lambda.runtime.events;
14+
15+
import lombok.*;
16+
17+
import java.util.Map;
18+
19+
/**
20+
* Represent the class for the Cognito User Pool Custom Message Lambda Trigger
21+
*
22+
* See <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-message.html">Custom Message Lambda Trigger</a>
23+
*
24+
* @author jvdl <[email protected]>
25+
*/
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
@NoArgsConstructor
29+
public class CognitoUserPoolCustomMessageEvent extends CognitoUserPoolEvent {
30+
/**
31+
* The request from the Amazon Cognito service.
32+
*/
33+
private Request request;
34+
35+
/**
36+
* The response from your Lambda trigger.
37+
*/
38+
private Response response;
39+
40+
@Builder(setterPrefix = "with")
41+
public CognitoUserPoolCustomMessageEvent(
42+
String version,
43+
String triggerSource,
44+
String region,
45+
String userPoolId,
46+
String userName,
47+
CallerContext callerContext,
48+
Request request,
49+
Response response) {
50+
super(version, triggerSource, region, userPoolId, userName, callerContext);
51+
this.request = request;
52+
this.response = response;
53+
}
54+
55+
@Data
56+
@EqualsAndHashCode(callSuper = true)
57+
@NoArgsConstructor
58+
public static class Request extends CognitoUserPoolEvent.Request {
59+
/**
60+
* 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.
61+
*/
62+
private Map<String, String> clientMetadata;
63+
/**
64+
* A string for you to use as the placeholder for the verification code in the custom message.
65+
*/
66+
private String codeParameter;
67+
/**
68+
* The username parameter. It is a required request parameter for the admin create user flow.
69+
*/
70+
private String usernameParameter;
71+
72+
@Builder(setterPrefix = "with")
73+
public Request(Map<String, String> userAttributes, Map<String, String> clientMetadata, String codeParameter, String usernameParameter) {
74+
super(userAttributes);
75+
this.clientMetadata = clientMetadata;
76+
this.codeParameter = codeParameter;
77+
this.usernameParameter = usernameParameter;
78+
}
79+
}
80+
81+
@Data
82+
@AllArgsConstructor
83+
@Builder(setterPrefix = "with")
84+
@NoArgsConstructor
85+
public static class Response {
86+
/**
87+
* The custom SMS message to be sent to your users. Must include the codeParameter value received in the request.
88+
*/
89+
private String smsMessage;
90+
/**
91+
* The custom email message to be sent to your users. Must include the codeParameter value received in the request.
92+
*/
93+
private String emailMessage;
94+
/**
95+
* The subject line for the custom message.
96+
*/
97+
private String emailSubject;
98+
}
99+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5+
* the License. A copy of the License is located at
6+
*
7+
* http://aws.amazon.com/apache2.0
8+
*
9+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
package com.amazonaws.services.lambda.runtime.events;
14+
15+
import lombok.*;
16+
17+
import java.util.Map;
18+
19+
/**
20+
* Represent the class for the Cognito User Pool Define Auth Challenge Lambda Trigger
21+
*
22+
* See <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-define-auth-challenge.html">Define Auth Challenge Lambda Trigger</a>
23+
*
24+
* @author jvdl <[email protected]>
25+
*/
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
@NoArgsConstructor
29+
public class CognitoUserPoolDefineAuthChallengeEvent extends CognitoUserPoolEvent {
30+
31+
/**
32+
* The request from the Amazon Cognito service.
33+
*/
34+
private Request request;
35+
36+
/**
37+
* The response from your Lambda trigger.
38+
*/
39+
private Response response;
40+
41+
@Builder(setterPrefix = "with")
42+
public CognitoUserPoolDefineAuthChallengeEvent(
43+
String version,
44+
String triggerSource,
45+
String region,
46+
String userPoolId,
47+
String userName,
48+
CallerContext callerContext,
49+
Request request,
50+
Response response) {
51+
super(version, triggerSource, region, userPoolId, userName, callerContext);
52+
this.request = request;
53+
this.response = response;
54+
}
55+
56+
@Data
57+
@EqualsAndHashCode(callSuper = true)
58+
@NoArgsConstructor
59+
public static class Request extends CognitoUserPoolEvent.Request {
60+
/**
61+
* 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.
62+
*/
63+
private Map<String, String> clientMetadata;
64+
65+
private ChallengeResult[] session;
66+
67+
/**
68+
* A Boolean that is populated when PreventUserExistenceErrors is set to ENABLED for your user pool client.
69+
* A value of true means that the user id (user name, email address, etc.) did not match any existing users.
70+
*/
71+
private boolean userNotFound;
72+
73+
@Builder(setterPrefix = "with")
74+
public Request(Map<String, String> userAttributes, Map<String, String> clientMetadata, ChallengeResult[] session, boolean userNotFound) {
75+
super(userAttributes);
76+
this.clientMetadata = clientMetadata;
77+
this.session = session;
78+
this.userNotFound = userNotFound;
79+
}
80+
}
81+
82+
@Data
83+
@AllArgsConstructor
84+
@Builder(setterPrefix = "with")
85+
@NoArgsConstructor
86+
public static class ChallengeResult {
87+
/**
88+
* The challenge type. One of: CUSTOM_CHALLENGE, SRP_A, PASSWORD_VERIFIER, SMS_MFA, DEVICE_SRP_AUTH, DEVICE_PASSWORD_VERIFIER, or ADMIN_NO_SRP_AUTH.
89+
*/
90+
private String challengeName;
91+
/**
92+
* Set to true if the user successfully completed the challenge, or false otherwise.
93+
*/
94+
private boolean challengeResult;
95+
/**
96+
* Your name for the custom challenge. Used only if challengeName is CUSTOM_CHALLENGE.
97+
*/
98+
private String challengeMetadata;
99+
}
100+
101+
@Data
102+
@AllArgsConstructor
103+
@Builder(setterPrefix = "with")
104+
@NoArgsConstructor
105+
public static class Response {
106+
/**
107+
* Name of the next challenge, if you want to present a new challenge to your user.
108+
*/
109+
private String challengeName;
110+
111+
/**
112+
* Set to true if you determine that the user has been sufficiently authenticated by completing the challenges, or false otherwise.
113+
*/
114+
private boolean issueTokens;
115+
116+
/**
117+
* Set to true if you want to terminate the current authentication process, or false otherwise.
118+
*/
119+
private boolean failAuthentication;
120+
}
121+
}

0 commit comments

Comments
 (0)