CCCT-1929 Refetch SSO Token On Invalid Token Error #3628
CCCT-1929 Refetch SSO Token On Invalid Token Error #3628conroy-ricketts wants to merge 5 commits intomasterfrom
Conversation
Tweaked the error handling for PersonalID API calls to crash the app when we see an INVALID_TOKEN error code given that we actually do not want to refetch the SSO token in this case.
…nto CCCT-1929-refetch-sso-token-on-invalid-token-error
📝 WalkthroughWalkthroughThe changes improve error handling in the PersonalID API handler by passing a descriptive error message when token validation fails, replacing a previous null error payload. Additionally, a comment in the base API handler was updated to clarify the scenarios where the TOKEN_INVALID_ERROR code is triggered, including missing session matching or missing Firebase UID. Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| // The firebase ID token is invalid (i.e. for PersonalID API calls, the configuration | ||
| // session auth was invalid as no session could be found with the token, or the firebase | ||
| // UID was not present when validating the token). |
There was a problem hiding this comment.
we should remove - The firebase ID token is invalid as that's being repeated later on and the configuration session auth is independent of Firebase.
| onFailure( | ||
| PersonalIdOrConnectApiErrorCodes.TOKEN_INVALID_ERROR, | ||
| new Throwable("The firebase ID token is invalid.") | ||
| ); |
There was a problem hiding this comment.
@conroy-ricketts As I understand, this INVALID_TOKEN error is thrown for 2 reasons, viz., if the session is invalid or the Firebase UID is invalid (only for Firebase OTP). So as per this implementation, it will only throw an exception as the 2nd reason only.
Can we make use of `errorSubCode '' (not sure if it's coming from INVALID_TOKEN) to exactly define the Throwable?
There was a problem hiding this comment.
Oh yeah thanks for catching that!
I did some more debugging to see what happens for other PersonalID API methods when the token is invalid (i.e. validateFirebaseIdToken(), addOrVerifyNameCall(), confirmBackupCode(), sendOtp(), and validateOtp())
Unfortunately, I saw that whenever we get an INVALID_TOKEN error code from Server, the error_sub_code is always empty. So, I tweaked the error message to be a bit more ambiguous - a82de79
…nto CCCT-1929-refetch-sso-token-on-invalid-token-error
Tweaked the code comment explaining TOKEN_INVALID_ERROR.
Tweaked the crash message for the TOKEN_INVALID error code.
CCCT-1929
Technical Summary
Practically speaking, there are only two scenarios in which Mobile will see an
INVALID_TOKENerror code from an API call in PersonalID:From my investigations, I confirmed that we will not be able to refetch the SSO token during the PersonalID signup flow simply because the user does not exist yet. Therefore, at least for PersonalID, we should not refetch the SSO token when we see the
INVALID_TOKENerror code.I had some discussions with the team, and the consensus seems to be that we should crash the app whenever we see either of those two scenarios that I listed above. So I tweaked the code to route a Throwable (created in the handleErrorCodeIfPresent() function in
PersonalIdApiHandler) to a new Runtime Exception (via the handle() function inPersonalIdOrConnectApiErrorHandler). Also, we should not change the error handling for API calls in Connect (the scope here is only PersonalID).Safety Assurance
Safety story
To verify these changes, I...
PersonalIdApiHandlerclass, set breakpoints inside both the API methodvalidateFirebaseIdToken()and the error code handler methodhandleErrorCodeIfPresent()(I later repeated this for all the other API methods that use a token)sessionData.setToken("invalid_token")INVALID_TOKENerror code"java.lang.RuntimeException: java.lang.Throwable: The configuration session auth is invalid or the firebase UID was not found."QA Plan
I do not think that QA is necessary for this.