Rework auth request code to provide useful error messages #172
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
Was getting json responses from the authn call that were of 'status' : 'MFA_ENROLL' , and had no 'sessionToken', but did have a
stateToken
. The app crashed with a JSON parse error with very little useful information.PROBLEM: Valid responses from the authn endpoint should not crash outright but rather provide the user with information to help diagnose the problem.
Solution
This PR restructures the authn response handling code to be more defensive in nature. It parses the incoming response json based on the status code, which looks sane based on the docks on okta. It adds a number of sanity checks and, if something goes awry the user will get a helpful error message and a copy of the response json in their command line output. The enum+switch structure makes it easy to expand coverage of the various various features of the okta API. Also added some doc strings and pointers to the Okta documentation where relevant.
In the same missing "sessionToken" scenario, our user will see this much more helpful message: