Skip to content

Conversation

@harsh62
Copy link
Member

@harsh62 harsh62 commented Nov 18, 2025

This pull request introduces several improvements and fixes to the authentication logic in the AWS Cognito Auth Plugin. The most significant changes include making token expiry checks more robust, ensuring keychain operations are only attempted when protected data is available, and simplifying error handling for session errors. Additionally, test mocks are enhanced to better simulate authentication flows.

Issue #

Description

General Checklist

  • Added new tests to cover change, if needed
  • Build succeeds with all target using Swift Package Manager
  • All unit tests pass
  • All integration tests pass
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Documentation update for the change if required
  • PR title conforms to conventional commit style
  • New or updated tests include Given When Then inline code documentation and are named accordingly testThing_condition_expectation()
  • If breaking change, documentation/changelog update with migration instructions

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@harsh62 harsh62 requested a review from a team as a code owner November 18, 2025 15:13
@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.66%. Comparing base (b4ba49e) to head (b379638).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4099      +/-   ##
==========================================
- Coverage   66.84%   66.66%   -0.18%     
==========================================
  Files        1129     1129              
  Lines       42540    42543       +3     
==========================================
- Hits        28435    28363      -72     
- Misses      14105    14180      +75     
Flag Coverage Δ
API_plugin_unit_test 68.41% <ø> (+0.02%) ⬆️
AWSPluginsCore 68.54% <ø> (ø)
Amplify 46.73% <ø> (-0.08%) ⬇️
Analytics_plugin_unit_test 84.84% <ø> (ø)
Auth_plugin_unit_test 71.93% <100.00%> (-0.57%) ⬇️
DataStore_plugin_unit_test 82.67% <ø> (+0.08%) ⬆️
Geo_plugin_unit_test 73.39% <ø> (ø)
Logging_plugin_unit_test 64.86% <ø> (ø)
Predictions_plugin_unit_test 33.89% <ø> (ø)
PushNotifications_plugin_unit_test 87.41% <ø> (ø)
Storage_plugin_unit_test 77.68% <ø> (ø)
unit_tests 66.66% <100.00%> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thisisabhash thisisabhash merged commit 99a521c into main Nov 18, 2025
143 of 167 checks passed
@thisisabhash thisisabhash deleted the random-logouts branch November 18, 2025 20:48
// During iOS prewarming or before first device unlock, keychain operations will fail
// because protected data is not available. Check proactively before any keychain/UserDefaults access.
#if canImport(UIKit) && !os(watchOS)
guard UIApplication.shared.isProtectedDataAvailable else {
Copy link

@ethan021021 ethan021021 Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thisisabhash @harsh62 without this check will the keychain clear if the app is prewarmed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. it would..

The reason we reverted that change because Xcode complained for accessing UIApplication outside of MainActor context.

We would have to rethink how to reintroduce that check in a safe way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does this PR fix any of the keychain clearing logic? I think that might be causing the random logouts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't fix the keychain clearing logic, but the PR introduces a very subtle fix of incorrectly signally sessionExpired that could be inadvertently resulting app developers logging out their users incorrectly.

Meanwhile, we are reconsidering the keychain clearing logic internally and will make changes accordingly.

Copy link

@ethan021021 ethan021021 Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so with this PR the keychain shouldn't be cleared if the app is prewarming and the user is logged in?

When was sessionExpired being incorrectly signaled?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so with this PR the keychain shouldn't be cleared if the app is prewarming and the user is logged in?

It still can, the fix was not applied.

When was sessionExpired being incorrectly signaled?

If an expired idToken was passed to Identity Pools during fetching an authenticated identity id and temporary credentials.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info!

Do you have an ETA on when the prewarming keychain clearing logic will be fixed? This is effecting a lot of our users unfortunately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I aiming to have something ready to be released next week.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants