Skip to content

Commit

Permalink
Merge pull request #40 from flowforge/logout-nodered
Browse files Browse the repository at this point in the history
Map FlowForge logout to nodered auth/revoke
  • Loading branch information
knolleary authored Jun 6, 2022
2 parents 9459aee + 193a48f commit ff6e029
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class AdminInterface {
await launcher.start(request.body.safe ? States.SAFE : States.RUNNING)
response.send({})
}
} else if (request.body.cmd === 'logout') { // logout:nodered(step-4)
await launcher.revokeUserToken(request.body.token) // logout:nodered(step-5)
response.send({})
} else if (request.body.cmd === 'shutdown') {
await launcher.stop()
response.send({})
Expand Down
22 changes: 22 additions & 0 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,28 @@ class Launcher {
this.state = States.STOPPED
}
}
async revokeUserToken (token) { // logout:nodered(step-5)
this.logBuffer.add({ level: 'system', msg: 'Node-RED logout requested' })
if (this.state !== States.RUNNING) {
// not running
return
}
try {
const adminAPI = `${this.settings.baseURL}/auth/revoke`
const json = { token: token, noRedirect: true }
const headers = {
authorization: 'Bearer ' + token,
'cache-control': 'no-cache',
'content-type': 'application/json',
'node-red-api-version': 'v2',
pragma: 'no-cache',
Referer: this.settings.baseURL
}
await got.post(adminAPI, { json, headers })
} catch (error) {
this.logBuffer.add({ level: 'system', msg: `Error logging out Node-RED: ${error.toString()}` })
}
}
}

module.exports = { Launcher, States }

0 comments on commit ff6e029

Please sign in to comment.