-
Notifications
You must be signed in to change notification settings - Fork 0
feat: resolve 10 implementable tech debt TODOs #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
68fd5e4
feat: add snapshot download endpoint (SEC3-S-06)
CybotTM fd12c04
fix: add crash atomicity for snapshot uploads (SEC4-S-11)
CybotTM 12777b0
feat: add device registration rate limit (SEC-S-10)
CybotTM 0d92ff5
feat: add WebSocket query param auth (SEC5-S-03)
CybotTM d9fa8f5
feat: add bucket creator role transfer (SEC3-S-08)
CybotTM 69da77c
refactor: remove Sessions.signingKey redundancy (SEC4-S-16)
CybotTM f194187
feat: add op table pruning after checkpoints (SEC5-S-14)
CybotTM ced5f99
fix: resolve test compilation and isolation issues across S1-S7 changes
CybotTM aee23c6
feat: use signing key fingerprint in QR codes (SC-03)
CybotTM bd13ea4
feat: include calendar events and info bank entries in snapshot hash …
CybotTM 8ac61d1
feat: add OkHttp TokenAuthenticator for automatic 401 re-authenticati…
CybotTM 50f2a19
chore: clarify deferred TODO comments with rationale
CybotTM ecebc68
fix: resolve Detekt warnings and Android compilation error
CybotTM afa4a72
fix: server WS close codes need Short type, test URL triggers Log.w
CybotTM 15724e7
fix: replace remaining wildcard imports flagged by Detekt
CybotTM db2ebe1
fix: address Copilot review findings
CybotTM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
android/app/src/main/java/com/kidsync/app/data/remote/interceptor/TokenAuthenticator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package com.kidsync.app.data.remote.interceptor | ||
|
|
||
| import android.content.SharedPreferences | ||
| import com.kidsync.app.domain.repository.AuthRepository | ||
| import kotlinx.coroutines.runBlocking | ||
| import okhttp3.Authenticator | ||
| import okhttp3.Request | ||
| import okhttp3.Response | ||
| import okhttp3.Route | ||
| import javax.inject.Inject | ||
| import javax.inject.Named | ||
|
|
||
| /** | ||
| * OkHttp Authenticator that handles 401 responses by re-authenticating | ||
| * via the Ed25519 challenge-response flow and retrying the failed request. | ||
| * | ||
| * This replaces the need for callers to handle 401s explicitly. When the | ||
| * server returns a 401 Unauthorized, OkHttp invokes this authenticator | ||
| * which: | ||
| * 1. Checks if a retry has already been attempted (prevents infinite loops) | ||
| * 2. Synchronizes concurrent 401s so only one re-authentication occurs | ||
| * 3. Performs challenge-response auth via AuthRepository | ||
| * 4. Retries the original request with the new session token | ||
| * | ||
| * Uses [dagger.Lazy] for AuthRepository to break the circular Hilt dependency: | ||
| * NetworkModule -> OkHttpClient -> TokenAuthenticator -> AuthRepository -> ApiService -> OkHttpClient | ||
| */ | ||
| class TokenAuthenticator @Inject constructor( | ||
| private val authRepository: dagger.Lazy<AuthRepository>, | ||
| @Named("encrypted_prefs") private val prefs: SharedPreferences | ||
| ) : Authenticator { | ||
|
|
||
| private val lock = Object() | ||
|
|
||
| /** | ||
| * Header added to retried requests to prevent infinite retry loops. | ||
| * If the retried request also gets a 401, we return null (give up). | ||
| */ | ||
| companion object { | ||
| internal const val HEADER_AUTH_RETRY = "X-Auth-Retry" | ||
| } | ||
|
|
||
| override fun authenticate(route: Route?, response: Response): Request? { | ||
| // Prevent infinite retry loops: if we already retried, give up | ||
| if (response.request.header(HEADER_AUTH_RETRY) != null) { | ||
| return null | ||
| } | ||
|
|
||
| synchronized(lock) { | ||
| // Check if another thread already refreshed the token since our | ||
| // request was made. Compare the token we sent with the current one. | ||
| val currentToken = prefs.getString(AuthInterceptor.PREF_SESSION_TOKEN, null) | ||
| val requestToken = response.request.header(AuthInterceptor.HEADER_AUTHORIZATION) | ||
| ?.removePrefix("Bearer ") | ||
|
|
||
| if (currentToken != null && currentToken != requestToken) { | ||
| // Token was already refreshed by another thread -- retry with it | ||
| return response.request.newBuilder() | ||
| .header(AuthInterceptor.HEADER_AUTHORIZATION, "Bearer $currentToken") | ||
| .header(HEADER_AUTH_RETRY, "true") | ||
| .build() | ||
| } | ||
|
|
||
| // Perform challenge-response authentication | ||
| val result = runBlocking { | ||
| authRepository.get().authenticate() | ||
| } | ||
|
|
||
| val session = result.getOrNull() ?: return null | ||
|
|
||
| return response.request.newBuilder() | ||
| .header(AuthInterceptor.HEADER_AUTHORIZATION, "Bearer ${session.sessionToken}") | ||
| .header(HEADER_AUTH_RETRY, "true") | ||
| .build() | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.