Skip to content

Commit

Permalink
feat(auth): Provide a clear message during getTokens that there are n…
Browse files Browse the repository at this point in the history
…o valid tokens on device (#3518)

* Provide a clear message to the customer that there are no valid tokens on the device to refresh.

* Provide further failure details in refresh error scenario
  • Loading branch information
tylerjroach authored Jan 26, 2024
1 parent bd69e14 commit 46fb3c3
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ForgotPasswordContinuation;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.NewPasswordContinuation;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler;
Expand Down Expand Up @@ -2045,17 +2046,21 @@ public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {

@Override
public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) {
signalTokensNotAvailable(null);
signalTokensNotAvailable(new CognitoNotAuthorizedException("No valid tokens on device."));
}

@Override
public void getMFACode(MultiFactorAuthenticationContinuation continuation) {
signalTokensNotAvailable(null);
signalTokensNotAvailable(
new Exception("MFA code requested during token refresh.")
);
}

@Override
public void authenticationChallenge(ChallengeContinuation continuation) {
signalTokensNotAvailable(null);
signalTokensNotAvailable(
new Exception("Authentication challenge requested during token refresh.")
);
}

@Override
Expand All @@ -2064,8 +2069,14 @@ public void onFailure(Exception exception) {
}

private void signalTokensNotAvailable(final Exception e) {
Exception exception;
if (e == null) {
exception = new Exception(("Unknown error occurred during token refresh."));
} else {
exception = e;
}
Log.w(TAG, "signalTokensNotAvailable");
callback.onError(new Exception("No cached session.", e));
callback.onError(new Exception("No cached session.", exception));
}
}
);
Expand Down

0 comments on commit 46fb3c3

Please sign in to comment.