-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misleading exception thrown when token refresh failed due to network error #2806
Comments
Hi @almosr-mikapaytech , Thanks for reporting this issue, our team will take a look and post once we have an update |
Hi @almosr-mikapaytech, thank you for providing the code snippet, and the steps. I've followed the steps to trigger fetchAuthSession() after changing the system date to few days later, disconnecting the local environment from the internet. Unfortunately, I was not able to replicate the issue (InvalidUserPoolConfigurationException). If you can, could you consider providing us Verbose level log with |
Hi @joon-won, |
Thank you @almosr-mikapaytech, with Verbose turned on you will be able to catch something like Could you share your AWSCognitoAuthSession Result after removing sensitive information from it? |
@joon-won I have made a mistake in the bug report, mixed up the chained calls. After reversed the order of the calls (so session is fetched first) I get back this session:
In this situation the app won't recover even after the network is working again. Refresh token should still be valid, but as it seems some other error blocks the refresh. |
No worries @almosr-mikapaytech, seems like the error message is now more relevant. If the app won't recover with
with |
@joon-won Thank you for the response. This is what I tried: RxAmplify.Auth.fetchAuthSession().flatMap {
(it as AWSCognitoAuthSession).accessToken?.let { Single.just(it) }
?: RxAmplify.Auth.fetchAuthSession(
AuthFetchSessionOptions.builder().forceRefresh(true).build()
).map {
(it as AWSCognitoAuthSession).accessToken ?: Exception("User token was not provided")
}
} Unfortunately, forcing the refresh does not resolve the issue. I still get back the same session error in the forced response:
|
Hi @almosr-mikapaytech, can you provide your
I ask because we have a couple similar issues for those exact conditions (e.g. #2725 and #2783) but the exception encountered there don't match your exception. (UnknownHostException vs your NotAuthorizedException and InvalidUserPoolConfigurationException) The only notable difference is also that you're using RxAmplify whereas they're not. Just as another troubleshooting tool, can you try making that call using the Kotlin library instead to see if you see the same error? |
Hi @vincetran,
Yes, these are all the conditions. Refresh token is valid for 365 days in our setup, so it must be valid 2 days later. To make things interesting, I tried to reproduce this issue today to test what happens when I call the standard method instead of the RxAmplify. While it was constantly happening on Friday, it did not happen even once today. I tested it with the exact same steps, always started with an app re-install to make sure nothing is left. Just to be clear: there are two , potentially separate issues mentioned in this ticket. One is the original issue that was reported for So, I am puzzled, not sure what can we do about the issue. My gut feeling is that it has something to do with time or date. Anyway, for your reference, here is the Amplify config file we are using. There is nothing special in it as far as I can tell. Please let me know if I could do anything else. |
Whether you are using standard Amplify callbacks, Kotlin Coroutines, or RxJava, each of these strategies should yield the same error messages. RxJava and Kotlin Coroutines simply wrap around the callback approach. The code paths do not differ. I think we can safely rule out the strategy (callbacks/rxjava,coroutines) used to call Amplify. Error 1: "The user pool configuration is missing or invalid." I think this is a bad message on our part. Auth.getCurrentUser calls fetchAuthSession() internally. If that call fails (ex: bad network), I think the above message will get triggered, which is not the correct message to display. This isn't the real message coming from the internal fetchAuthSession call. Error 2: "NotAuthorizedException(message=Token is not from a supported provider of this identity pool.)" This is likely the failure happening inside that internal fetchAuthSession call, as well as the message you are seeing if you call fetchAuthSession before getCurrentUser. The important thing to note on this issue: "Token is not from a supported provider of this identity pool." is that this did not come from a locally constructed error message. This message is not hardcoded in Amplify and could have only come from the Cognito service. With this context in mind, can you share a bit more about the authentication methods that are available in your application? I see "ADMIN_NO_SRP_AUTH" and "USER_PASSWORD_AUTH", but do have "ALLOW_REFRESH_TOKEN_AUTH" as an authentication flow in the Cognito console? It says its always enabled, but its odd that my Auth apps show the option as always selected where I don't see it in yours. Next, do you have any social sign ins? I see that you have hosted UI authentication configured in your application. Do you have multiple login flows in your application (ex: native and hosted ui)? I see that you have token revocation enabled. Do you have any service side processes that could be revoking token access, or signing out with global sign out = "true". This could revoke tokens on other devices. "Token is not from a supported provider of this identity pool." is a very specific error coming from the service so we should try and focus on what is causing this exact message. |
Hi @tylerjroach, The app uses user-password authentication method only, the user is created programmatically on service side and one time password is used for authentication. Direct sign by using with email or any other method (e.g. social sign in) is not available. In the console the option for ALLOW_REFRESH_TOKEN_AUTH is disabled: I asked the backend devs regarding forced sign out, they told me there is no such flow implemented currently. Would it be possible to find out from service-side logs why Cognito sent back that specific error? |
@almosr-mikapaytech How many times have you seen this issue? I would triple check all of the values on the console side to make sure they match what is being used in amplifyconfiguration. In researching what this error message means, I came across "This issue usually occurs if the app client used for authenticating the user is different from the app client configured with the identity pool. You may confirm this by checking if the aud value in the identity token is different from what's configured in your identity pool." |
Hi @tylerjroach, I'm a backend developer on the @almosr-mikapaytech team. After enabling the cloud trail for the cognito and management events and with your comments on this thread, we could identify that the problem was caused by the fact that one of our User Pools was not registered as a valid identity provider for our Identity Pool. It is still weird that Identity Pool errors revoked User Pool tokens, but the issue is solved. |
Great to hear, thank you for following up to let us know the issue. This helps us troubleshoot future investigations! |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Before opening, please confirm:
Language and Async Model
Kotlin
Amplify Categories
Authentication
Gradle script dependencies
Environment information
Please include any relevant guides or documentation you're referencing
No response
Describe the bug
When identity token expired and refresh token cannot be used due to network error then Amplify throws an unrelated error:
It is possible to recover from this situation when network access is restored.
Reproduction steps (if applicable)
Code Snippet
Log output
amplifyconfiguration.json
No response
GraphQL Schema
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: