From 5b850ae38aa7f8e0e947989ca9c9d89e4b10015c Mon Sep 17 00:00:00 2001 From: Johan le stickman Date: Wed, 1 Nov 2023 19:26:21 +0100 Subject: [PATCH] Fix 'no challenge was given' --- index.js | 21 ++++++++++++++++++++- package.json | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b2aa7cf..a0a22d6 100644 --- a/index.js +++ b/index.js @@ -258,7 +258,26 @@ async function authentificate(){ }) if(this.options.verbose) console.info("Got challenge:", challenge?.result?.challenge || challenge?.msg || challenge) if(!challenge.success) return challenge - if(!challenge?.result?.challenge) return { success: false, msg: `No challenge was given for an unknown reason: ${challenge?.msg || challenge?.message || challenge?.result?.msg || challenge?.result?.message || challenge?.status_code}`, challenge } + + // Si on a pas de challenge + if(!challenge?.result?.challenge){ + // Si on est déjà connecté + if(challenge?.result?.logged_in){ + // On fait une requête qui nécessite d'être connecté + if(this.options.verbose) console.info("Seems we were already logged in, double-checking...") + var freeboxSystem = await this.fetch({ + url: "v8/system", + parseJson: true + }) + if(this.options.verbose) console.info("Got freebox system (for double-checking the login):", freeboxSystem) + + // Si ça a marché, on retourne qu'on est connecté + if(freeboxSystem.success) return { success: true, freebox: this.freebox } + } + + // On dit que le challenge a pas marché + return { success: false, msg: `No challenge was given for an unknown reason: ${challenge?.msg || challenge?.message || challenge?.result?.msg || challenge?.result?.message || challenge?.status_code}`, challenge } + } // Déterminer le mot de passe var password = createHmac("sha1", this.options.appToken).update(challenge?.result?.challenge).digest("hex") diff --git a/package.json b/package.json index 99e88e4..1b64f69 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "freebox-wrapper", - "version": "1.0.4", + "version": "1.0.5", "description": "Un wrapper pour l'API de Freebox OS, gère la connexion et facilite les requêtes.", "main": "index.js", "keywords": [