Skip to content

Commit 73bb3e4

Browse files
authored
fix: honor authenticationFlowType from config (#2377)
* fix: honor authenticationFlowType from config if set * PR feedback
1 parent 04f8e88 commit 73bb3e4

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

aws-android-sdk-mobile-client/src/main/java/com/amazonaws/mobile/client/AWSMobileClient.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,20 +1206,33 @@ public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {
12061206
@Override
12071207
public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) {
12081208
Log.d(TAG, "Sending password.");
1209+
final HashMap<String, String> authParameters = new HashMap<>();
1210+
// Check if the auth flow type setting is in the configuration.
1211+
boolean authFlowTypeInConfig =
1212+
awsConfiguration.optJsonObject(AUTH_KEY) != null &&
1213+
awsConfiguration.optJsonObject(AUTH_KEY).has("authenticationFlowType");
1214+
12091215
try {
1210-
if (
1211-
awsConfiguration.optJsonObject(AUTH_KEY) != null &&
1212-
awsConfiguration.optJsonObject(AUTH_KEY).has("authenticationFlowType") &&
1213-
awsConfiguration.optJsonObject(AUTH_KEY).getString("authenticationFlowType").equals("CUSTOM_AUTH")
1214-
) {
1215-
final HashMap<String, String> authParameters = new HashMap<String, String>();
1216+
String authFlowType = authFlowTypeInConfig ?
1217+
awsConfiguration.optJsonObject(AUTH_KEY).getString("authenticationFlowType") :
1218+
null;
1219+
// If there's a value in the config and it's CUSTOM_AUTH
1220+
if (authFlowTypeInConfig && "CUSTOM_AUTH".equals(authFlowType)) {
12161221
if (password != null) {
12171222
authenticationContinuation.setAuthenticationDetails(new AuthenticationDetails(username, password, authParameters, validationData));
12181223
} else {
12191224
authenticationContinuation.setAuthenticationDetails(new AuthenticationDetails(username, authParameters, validationData));
12201225
}
12211226
} else {
1222-
authenticationContinuation.setAuthenticationDetails(new AuthenticationDetails(username, password, validationData));
1227+
// Otherwise, create the AuthenticationDetails instance using the constructor below
1228+
// which will default the auth flow to CHLG_TYPE_USER_PASSWORD_VERIFIER
1229+
AuthenticationDetails authenticationDetails = new AuthenticationDetails(username, password, validationData);
1230+
if (authFlowTypeInConfig) {
1231+
// If there's an auth flow type value in the config, use that value instead.
1232+
// The field names are very misleading.
1233+
authenticationDetails.setAuthenticationType(awsConfiguration.optJsonObject(AUTH_KEY).getString("authenticationFlowType"));
1234+
}
1235+
authenticationContinuation.setAuthenticationDetails(authenticationDetails);
12231236
}
12241237
} catch (JSONException e) {
12251238
e.printStackTrace();

0 commit comments

Comments
 (0)