2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-01 20:30:48 +00:00

Fix #275 - Add HTTP --basic-auth-{username,password} CLI flags (#444)

This commit is contained in:
Devin Buhl 2017-10-05 18:44:03 -04:00 committed by Ronan Jouchet
parent 3e7cec2ecb
commit 4c581f9067
5 changed files with 30 additions and 1 deletions

View File

@ -48,6 +48,14 @@ if (appArgs.diskCacheSize) {
app.commandLine.appendSwitch('disk-cache-size', appArgs.diskCacheSize); app.commandLine.appendSwitch('disk-cache-size', appArgs.diskCacheSize);
} }
if (appArgs.basicAuthUsername) {
app.commandLine.appendSwitch('basic-auth-username', appArgs.basicAuthUsername);
}
if (appArgs.basicAuthPassword) {
app.commandLine.appendSwitch('basic-auth-password', appArgs.basicAuthPassword);
}
// do nothing for setDockBadge if not OSX // do nothing for setDockBadge if not OSX
let setDockBadge = () => {}; let setDockBadge = () => {};
@ -100,7 +108,12 @@ app.on('ready', () => {
app.on('login', (event, webContents, request, authInfo, callback) => { app.on('login', (event, webContents, request, authInfo, callback) => {
// for http authentication // for http authentication
event.preventDefault(); event.preventDefault();
createLoginWindow(callback);
if (appArgs.basicAuthUsername !== null && appArgs.basicAuthPassword !== null) {
callback(appArgs.basicAuthUsername, appArgs.basicAuthPassword);
} else {
createLoginWindow(callback);
}
}); });
if (appArgs.singleInstance) { if (appArgs.singleInstance) {

View File

@ -40,6 +40,8 @@
- [[zoom]](#zoom) - [[zoom]](#zoom)
- [[crash-reporter]](#crash-reporter) - [[crash-reporter]](#crash-reporter)
- [[single-instance]](#single-instance) - [[single-instance]](#single-instance)
- [[basic-auth-username]](#basic-auth-username)
- [[basic-auth-password]](#basic-auth-username)
- [Programmatic API](#programmatic-api) - [Programmatic API](#programmatic-api)
## Command Line ## Command Line
@ -408,6 +410,14 @@ Sets a default zoom factor to be used when the app is opened, defaults to `1.0`.
Prevents application from being run multiple times. If such an attempt occurs the already running instance is brought to front. Prevents application from being run multiple times. If such an attempt occurs the already running instance is brought to front.
#### [basic-auth-username]
```
--basic-auth-username <value> --basic-auth-password <value>
```
Set basic http(s) auth via the command line to have the app automatically log you in to a protected site. Both fields are required if one is set.
#### [processEnvs] #### [processEnvs]
``` ```

View File

@ -46,6 +46,8 @@ function selectAppArgs(options) {
win32metadata: options.win32metadata, win32metadata: options.win32metadata,
versionString: options.versionString, versionString: options.versionString,
processEnvs: options.processEnvs, processEnvs: options.processEnvs,
basicAuthUsername: options.basicAuthUsername,
basicAuthPassword: options.basicAuthPassword,
}; };
} }

View File

@ -82,6 +82,8 @@ if (require.main === module) {
.option('--crash-reporter <value>', 'remote server URL to send crash reports') .option('--crash-reporter <value>', 'remote server URL to send crash reports')
.option('--single-instance', 'allow only a single instance of the application') .option('--single-instance', 'allow only a single instance of the application')
.option('--processEnvs <json-string>', 'a JSON string of key/value pairs to be set as environment variables before any browser windows are opened.', getProcessEnvs) .option('--processEnvs <json-string>', 'a JSON string of key/value pairs to be set as environment variables before any browser windows are opened.', getProcessEnvs)
.option('--basic-auth-username <value>', 'basic http(s) auth username')
.option('--basic-auth-password <value>', 'basic http(s) auth password')
.parse(process.argv); .parse(process.argv);
if (!process.argv.slice(2).length) { if (!process.argv.slice(2).length) {

View File

@ -66,6 +66,8 @@ export default function (inpOptions) {
FileDescription: inpOptions.name, FileDescription: inpOptions.name,
}, },
processEnvs: inpOptions.processEnvs, processEnvs: inpOptions.processEnvs,
basicAuthUsername: inpOptions.basicAuthUsername || null,
basicAuthPassword: inpOptions.basicAuthPassword || null,
}; };
if (options.verbose) { if (options.verbose) {