Validate the JSON response status when MFA push polling #414
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Statement
When a user's okta password is expired, Push verification fails with a cryptic JSON parse error:
Exception in thread "main" org.json.JSONException: JSONObject["factorResult"] not found.
at org.json.JSONObject.get(JSONObject.java:572)
at org.json.JSONObject.getString(JSONObject.java:859)
at com.okta.tools.authentication.OktaMFA.handlePushPolling(OktaMFA.java:307)
at com.okta.tools.authentication.OktaMFA.verifyAnswer(OktaMFA.java:285)
at com.okta.tools.authentication.OktaMFA.pushFactor(OktaMFA.java:242)
at com.okta.tools.authentication.OktaMFA.getSessionToken(OktaMFA.java:103)
at com.okta.tools.authentication.OktaMFA.promptForFactor(OktaMFA.java:64)
at com.okta.tools.authentication.OktaAuthentication.getOktaSessionToken(OktaAuthentication.java:87)
at com.okta.tools.saml.OktaSaml.getSamlResponse(OktaSaml.java:47)
at com.okta.tools.OktaAwsCliAssumeRole.doRequest(OktaAwsCliAssumeRole.java:132)
at com.okta.tools.OktaAwsCliAssumeRole.run(OktaAwsCliAssumeRole.java:102)
at com.okta.tools.WithOkta.main(WithOkta.java:28)
Solution
We can use the existing validateStatus method to validate the status of the json response for each poll response.