Skip to content

Commit

Permalink
Fix 'no challenge was given'
Browse files Browse the repository at this point in the history
  • Loading branch information
johan-perso committed Nov 1, 2023
1 parent d4fd0d9 commit 5b850ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit 5b850ae

Please sign in to comment.