-
Notifications
You must be signed in to change notification settings - Fork 199
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
401 Unauthorized Errors Due to missing token in Amplify iOS SDK (Version 2.33.6) #3926
Comments
How long do you think a while is? Is it possible the refresh token expired? How long are refresh token's set to be valid on your account? Once a refresh token is expired, the user will have to logout and back in. I do not believe the referenced issue you pointed to would be related. |
@tylerjroach we set the validity of the refresh token to 10 years and the access token to 15 minutes. Our app has only been live for more than a year, so we expect the user to remain logged in even after they update the app. |
@jerfranco-deloitte Some of the cases where a refresh token could be invalidated are:
I have a few other questions:
Did this also include an update the Amplify library? Any other info you could provide that could narrow down the investigation? |
@jerfranco-deloitte Can you try a small change and see if that works?
Just change your above code to something as below and see if that resolved the issue?
Looking forward to your feedback, thanks. |
@harish-suthar, here are the answers to your questions:
We're using the same app client ID
Device tracking is turned off in Cognito User Pools
Here's my configuration file: {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "ap-southeast-2:REDACTED",
"Region": "ap-southeast-2"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "ap-southeast-2_REDACTED",
"AppClientId": "REDACTED",
"Region": "ap-southeast-2",
}
}
}
}
}
}
This issue started to happen after we upgraded to 2.33.6
Users can log into the app via email and password, but we still can't determine which type of users are encountering this issue. |
@jerfranco-deloitte Are you somehow able to grab the verbose logs when this issue happens? |
@harsh62 How do you access amplify verbose logs? |
You can enable verbose logging to the console by doing this before calling
|
@harsh62 I mean is there any way I can send these verbose logs to a logging service, to see the production logs as this issue is not reproducible easily and we are getting reports of this from production app for some users. |
You will need to setup the logging category to send the logs to AWSCloudWatch. The setup guide is available here: https://docs.amplify.aws/swift/build-a-backend/add-aws-services/logging/set-up-logging/. |
@harish-suthar @harsh62 Thanks for the advice. This might help since we can't easily reproduce the production issue in our non-prod environments. @harsh62, do we need to set |
Describe the bug
We are experiencing intermittent 401 Unauthorized errors in our iOS app using AWS Amplify SDK version 2.33.6. The issue seems to be affecting some users but not all, and we have been unable to replicate the problem internally. The errors appear to be related to missing or invalid tokens, with most server logs indicating missing tokens as the primary cause.
Steps To Reproduce
Expected behavior
The fetchAuthSession() method should automatically refresh expired tokens or provide valid tokens, preventing 401 errors due to missing or invalid tokens.
Amplify Framework Version
2.33.6
Amplify Categories
Auth
Dependency manager
Swift PM
Swift version
5
CLI version
2
Xcode version
16.1
Relevant log output
Missing tokens
Is this a regression?
Yes
Regression additional context
No response
Platforms
iOS
OS Version
18.1, 17.4
Device
iPhone 16, iPhone 12
Specific to simulators
No response
Additional context
The text was updated successfully, but these errors were encountered: