Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for httpNodeAuth #341

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/
/node_modules/
var/
16 changes: 15 additions & 1 deletion lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,22 @@ class Launcher {
// The `httpNodeAuth` config is passed straight through to Node-RED
// It is however sanitised in config.js to ensure it is an object
// containing `user` and `pass` properties.
settings.httpNodeAuth = this.config.httpNodeAuth
settings.flowforge.httpNodeAuth = {
type: 'basic',
...this.config.httpNodeAuth
}
} else if (this.settings?.security?.httpNodeAuth) {
settings.flowforge.httpNodeAuth = {
...this.settings.security.httpNodeAuth,
bin: path.join(__dirname, 'plugins/node_modules/@flowfuse/flowfuse-auth/httpAuthMiddleware.js')
}
if (settings.flowforge.httpNodeAuth.type === 'ff-user') {
// Add the ff-auth plugin
settings.nodesDir = settings.nodesDir || []
settings.nodesDir.push(path.join(__dirname, 'plugins', 'node_modules', '@flowfuse', 'flowfuse-auth'))
}
}

await fs.writeFile(this.files.userSettings, JSON.stringify(settings))
}

Expand Down
80 changes: 80 additions & 0 deletions lib/plugins/node_modules/@flowfuse/flowfuse-auth/adminAuth.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

143 changes: 143 additions & 0 deletions lib/plugins/node_modules/@flowfuse/flowfuse-auth/httpAuthMiddleware.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/plugins/node_modules/@flowfuse/flowfuse-auth/httpAuthPlugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions lib/plugins/node_modules/@flowfuse/flowfuse-auth/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions lib/plugins/node_modules/@flowfuse/flowfuse-auth/strategy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions lib/template/template-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,25 @@ if (settings.https) {
if (settings.httpStatic) {
runtimeSettings.httpStatic = settings.httpStatic
}

if (settings.httpNodeAuth && typeof settings.httpNodeAuth === 'object') {
if (settings.flowforge.httpNodeAuth?.user && settings.flowforge.httpNodeAuth?.pass) {
runtimeSettings.httpNodeAuth = {
user: settings.httpNodeAuth.user,
pass: settings.httpNodeAuth.pass
user: settings.flowforge.httpNodeAuth.user,
pass: settings.flowforge.httpNodeAuth.pass
}
} else if (settings.flowforge.httpNodeAuth?.type === 'ff-user') {
const ffAuthMiddleware = require(settings.flowforge.httpNodeAuth.bin).init({
type: 'flowforge-user',
// baseURL is the url of the http endpoints. We don't know the external
// ip/name of the device, so we use a placeholder. The code only needs the
// pathname (ie '/') from this URL - the domain/etc is not used.
baseURL: 'https://example.com/',
forgeURL: settings.flowforge.forgeURL,
clientID: settings.flowforge.httpNodeAuth.clientID,
clientSecret: settings.flowforge.httpNodeAuth.clientSecret
})
runtimeSettings.httpNodeMiddleware = ffAuthMiddleware
runtimeSettings.ui = {
middleware: ffAuthMiddleware
}
}
module.exports = runtimeSettings
Loading