fix: retry every Shaarli 401 with a server-clock-recalibrated JWT (2.14.3) #1
@@ -28,16 +28,17 @@ class AuthInterceptor @Inject constructor(
|
||||
return chain.proceed(original)
|
||||
}
|
||||
|
||||
// Remember whether the first token was generated before we knew the server time. If
|
||||
// so, a 401 is ambiguous: bad secret, or device clock skew pushed `iat` outside
|
||||
// Shaarli's tolerance. The Date header of the failed response calibrates our clock,
|
||||
// so retry exactly once with a regenerated token.
|
||||
val clockWasUnknown = !serverClock.isSynced
|
||||
|
||||
// A 401 is ambiguous: bad secret, or device/server clock skew pushed `iat`
|
||||
// outside Shaarli's tolerance. The Date header of the failed response is the
|
||||
// freshest server-clock estimate we have, so retry exactly once with a
|
||||
// regenerated token, on every 401 — not only when the clock was never synced.
|
||||
// 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))
|
||||
serverClock.syncFromResponse(response)
|
||||
|
||||
if (response.code == 401 && clockWasUnknown) {
|
||||
if (response.code == 401) {
|
||||
response.close()
|
||||
response = chain.proceed(original.withAuth(apiSecret))
|
||||
serverClock.syncFromResponse(response)
|
||||
|
||||
@@ -52,8 +52,11 @@ constructor(private val api: ShaarliApi, private val tokenManager: TokenManager)
|
||||
401,
|
||||
403 ->
|
||||
Exception(
|
||||
"HTTP ${e.code()} - Secret API refuse. Copie le champ « Secret API » de " +
|
||||
"Shaarli (Configuration -> Securite) : ce n'est PAS ton mot de passe " +
|
||||
"HTTP ${e.code()} - Secret API refuse. L'application a deja reessaye " +
|
||||
"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 », " +
|
||||
"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))
|
||||
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,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
textAlign = TextAlign.Center,
|
||||
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
#Thu Apr 23 19:46:44 2026
|
||||
VERSION_NAME=2.14.2
|
||||
VERSION_CODE=43
|
||||
VERSION_NAME=2.14.3
|
||||
VERSION_CODE=44
|
||||
Reference in New Issue
Block a user