Commit c3c46ff
committed
Fix Login State Loss and OAuth Flow Interruption
This commit addresses a critical issue where the application would lose its authentication state and reset to the login screen when the user switched applications during the OAuth flow (e.g., to retrieve credentials from a password manager) or when the OS killed the background process.
Key Changes:
1. **Manifest Configuration**:
- Updated LoginActivity launchMode from singleTask to singleTop. This prevents the activity from being unnecessarily destroyed and recreated when receiving the OAuth redirect intent, preserving the activity stack.
2. **ViewModel Updates (AuthenticationViewModel.kt)**:
- Changed PKCE state properties (codeVerifier, codeChallenge, oidcState) from immutable �al to mutable �ar. This allows these values to be restored after process death, which is essential for completing the OAuth handshake.
3. **State Persistence (LoginActivity.kt)**:
- Implemented saveAuthState() and
estoreAuthState() methods using SharedPreferences. This ensures that the PKCE parameters survive process death and activity recreation, which savedInstanceState alone was not reliably handling for this specific flow.
- Added clearAuthState() to remove temporary authentication data upon successful login or error, ensuring security and cleanliness.
- Integrated these methods into the lifecycle: saving state before launching the browser and restoring it in onCreate if needed.
4. **OAuth Redirect Handling**:
- Added 'trampoline' logic in onCreate to correctly handle OAuth redirect intents. If the activity is not the task root, it relaunches itself with CLEAR_TOP and SINGLE_TOP flags to bring the existing instance to the front without losing state.
- Modified handleDeepLink to explicitly ignore OAuth redirect intents (checking for 'code' and 'error' parameters), preventing them from being misidentified as regular deep links.
This comprehensive fix ensures a robust login experience even on devices with aggressive background process killing or when users multitask during authentication.1 parent 252eb16 commit c3c46ff
3 files changed
Lines changed: 53 additions & 5 deletions
File tree
- opencloudApp/src/main
- java/eu/opencloud/android/presentation/authentication
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
| 239 | + | |
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
76 | | - | |
77 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
Lines changed: 49 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
| |||
118 | 121 | | |
119 | 122 | | |
120 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
121 | 134 | | |
122 | 135 | | |
123 | 136 | | |
| |||
142 | 155 | | |
143 | 156 | | |
144 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
145 | 161 | | |
146 | 162 | | |
147 | 163 | | |
| |||
211 | 227 | | |
212 | 228 | | |
213 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
214 | 237 | | |
215 | 238 | | |
216 | 239 | | |
217 | | - | |
| 240 | + | |
218 | 241 | | |
219 | 242 | | |
220 | 243 | | |
| |||
486 | 509 | | |
487 | 510 | | |
488 | 511 | | |
| 512 | + | |
489 | 513 | | |
490 | 514 | | |
491 | 515 | | |
| |||
515 | 539 | | |
516 | 540 | | |
517 | 541 | | |
| 542 | + | |
518 | 543 | | |
519 | 544 | | |
520 | 545 | | |
| |||
570 | 595 | | |
571 | 596 | | |
572 | 597 | | |
| 598 | + | |
573 | 599 | | |
574 | 600 | | |
575 | 601 | | |
| |||
894 | 920 | | |
895 | 921 | | |
896 | 922 | | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
897 | 945 | | |
0 commit comments