Merge pull request 'fix: retry every Shaarli 401 with a server-clock-recalibrated JWT (2.14.3)' (#1) from fix/shaarli-401-retry into main

This commit was merged in pull request #1.
This commit is contained in:
2026-11-01 12:19:30 -05:00
4 changed files with 16 additions and 12 deletions
@@ -28,16 +28,17 @@ class AuthInterceptor @Inject constructor(
return chain.proceed(original) return chain.proceed(original)
} }
// Remember whether the first token was generated before we knew the server time. If // A 401 is ambiguous: bad secret, or device/server clock skew pushed `iat`
// so, a 401 is ambiguous: bad secret, or device clock skew pushed `iat` outside // outside Shaarli's tolerance. The Date header of the failed response is the
// Shaarli's tolerance. The Date header of the failed response calibrates our clock, // freshest server-clock estimate we have, so retry exactly once with a
// so retry exactly once with a regenerated token. // regenerated token, on every 401 — not only when the clock was never synced.
val clockWasUnknown = !serverClock.isSynced // Previously the retry was gated on `!serverClock.isSynced`, so once an offset
// had been stored (possibly from a stale or proxy-derived Date header) it was
// trusted for the rest of the process and a correct secret could fail forever.
var response = chain.proceed(original.withAuth(apiSecret)) var response = chain.proceed(original.withAuth(apiSecret))
serverClock.syncFromResponse(response) serverClock.syncFromResponse(response)
if (response.code == 401 && clockWasUnknown) { if (response.code == 401) {
response.close() response.close()
response = chain.proceed(original.withAuth(apiSecret)) response = chain.proceed(original.withAuth(apiSecret))
serverClock.syncFromResponse(response) serverClock.syncFromResponse(response)
@@ -52,8 +52,11 @@ constructor(private val api: ShaarliApi, private val tokenManager: TokenManager)
401, 401,
403 -> 403 ->
Exception( Exception(
"HTTP ${e.code()} - Secret API refuse. Copie le champ « Secret API » de " + "HTTP ${e.code()} - Secret API refuse. L'application a deja reessaye " +
"Shaarli (Configuration -> Securite) : ce n'est PAS ton mot de passe " + "avec l'horloge du serveur : un 401 persistant signifie que le " +
"secret saisi ne correspond plus a celui affiche ACTUELLEMENT dans " +
"Shaarli. Copie le champ « Secret API » de Shaarli " +
"(Configuration -> Securite) : ce n'est PAS ton mot de passe " +
"de connexion. Si tu as utilise « Deconnexion de tous les appareils », " + "de connexion. Si tu as utilise « Deconnexion de tous les appareils », " +
"le secret a ete regenere et il faut ressaisir le nouveau." "le secret a ete regenere et il faut ressaisir le nouveau."
) )
@@ -190,7 +190,7 @@ fun LoginScreen(onLoginSuccess: () -> Unit, viewModel: LoginViewModel = hiltView
Spacer(modifier = Modifier.height(24.dp)) Spacer(modifier = Modifier.height(24.dp))
Text( Text(
text = text =
"Find your API secret in Shaarli's\n\"Tools\" → \"Configure your Shaarli\"", "Find your API secret in Shaarli's\n\"Configuration\" → \"Security\" — it is not\nyour login password",
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.outline, color = MaterialTheme.colorScheme.outline,
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
+2 -2
View File
@@ -1,3 +1,3 @@
#Thu Apr 23 19:46:44 2026 #Thu Apr 23 19:46:44 2026
VERSION_NAME=2.14.2 VERSION_NAME=2.14.3
VERSION_CODE=43 VERSION_CODE=44