1Password Integration
The op signin command doesn't allow the master password to be passed directly to the command; instead, you have to enter it interactively:
$ op signin my.1password.com [email] [key]
Enter the password for [email] at my.1password.com:
When running this, the stdout listener in process.js doesn't seem to receive the prompt, so there's no way to know when to input the password. From reading about this, this could potentially be due to op not flushing the stdout buffer, but if that's the case, it doesn't look like there's any way to force that to happen. Or it might be something else that I'm missing.
The dirty way: we can use child_process.spawnSync instead of child_process.spawn, supplying the password as input option. POC:
const { spawn, spawnSync } = require('child_process')
class ProcessSpawner {
constructor(command, args) {
this.command = command
this.args = args
this.data = ""
this.error = ""
}
...
executeSync(input) {
const process = spawnSync(this.command, this.args, { input: input })
return process
}
}
p = new ProcessSpawner('op', ['signin', 'my.1password.com', '[email protected]', MY-SECRET-KEY])
const { stdout, stderr } = p.executeSync("super-secure-password\n")
console.log(stdout.toString())
>>> export OP_SESSION_my="NEW_SESSION_KEY"
>>> # This command is meant to be used with your shell's eval function.
>>> # Run 'eval $(op signin my)' to sign into your 1Password account.
>>> # If you wish to use the session token itself, pass the --output=raw flag value.
Still looking for a way to make it work with normal spawn though...
Thanks, that seems to work. I've started working on it here: https://github.com/minbrowser/min/tree/1password
There seem to be some other strange differences between spawn and spawnSync as well; for example, using this for executeSync:
executeSync(input) {
const process = spawnSync(this.command, this.args, { input: input, encoding: "utf8" })
return process.output[1].slice(0, -1)
}
the synchronous version works:
let process = new ProcessSpawner(command, ['list', 'items', '--session=' + this.sessionKey])
let data = process.executeSync();
but the async version returns no output:
let process = new ProcessSpawner(command, ['list', 'items', '--session=' + this.sessionKey])
let data = await process.execute();
I haven't checked the list command behavior, but what this op util does with inputs/outputs for signin command is funky: we don't receive any data on the stdout pipe because it WRITES the prompt to stdin. So it's kind of using an OS loophole to be... more secure, I guess?
You can check this by providing custom stdio param to the spawn method. If you call
const p = spawn(this.command, this.args, { stdio: ['pipe', 'inherit', 'pipe'] })
which redirects the child's stdout to parent's stdout, then we get nothing in the console. But if you call
const p = spawn(this.command, this.args, { stdio: ['inherit', 'pipe', 'pipe'] })
which connects's parent's stdin pipe to the child process, then we can see the prompt in the console.
I tried to play around that by providing custom Stream objects to the spawn's stdio parameter, but with no success so far...
That's very strange, and it doesn't look like just attaching a listener to process.stdin works either. I suppose if there isn't a workaround, it might be fine to just make everything synchronous, since the times this code would be running (after clicking on the key or typing your password) would be times that you would be waiting for the result and not doing anything else anyway. The only issue with that might be that I think signin makes a network request (since it seems to update the password store when you do that), so if you have slow internet, the app could potentially freeze for a long time.
Can we just wrap the executeSync with a Promise to unblock the main thread?
Even if you put it inside a promise, everything's still going to be single-threaded, so it's still going to prevent anything else from running. For example, running this will freeze the app:
new Promise(function(resolve, reject) {
while (true) {}
})
However, it looks like we could run the child process from within a web worker, which would be on a separate thread: https://github.com/electron/electron/blob/6f91af93433df4e9c0e7fb592e5b2dcb0b1c7888/docs/tutorial/multithreading.md
Alternatively, we could make a script that wraps the 1password util, and run that as a child process inside the app (using electron_run_as_node). The child process would be frozen for the duration of the executeSync call, but since it would be run asynchronously from the rest of the app, that would be fine.
Hi! I use 1password all the time, and I was wondering how progress is coming along, and if the 1password branch is stable enough to try?
Also, thank you both for all of the hard work!
I don't think it actually works yet, so probably not. I've been fairly busy with other stuff recently, but I'll hopefully get back to working on it soon.
Ah, got it. Well, good luck!
I made the synchronous commands run inside a worker so that they don't block the app in b1fc23538884f87496ac1d59699a072e4e67b81c; that seems to work well enough, although I'm not really happy with it.
BTW @flber filling passwords should work fine now if you want to try it. There's no setup instructions yet, so make sure you have the 1password CLI tool installed first.
This should be fully working now, PR: #971
When 1password has multiple stored user:password combinations it defaults to either one or the other and doesn't provide the user with an option, resulting in an incorrect password for one of the logins. [edit] It seems to pick the most recently added password
It works for me with multiple accounts; what website is this on? Do either of the password items have multiple "website" entries set for them?
This is on https://app.schoology.com/login. Neither of the items have multiple website entries. They had different urls (though I think they both redirected to the same place), so I changed them to the same url and tried again. Then I tried making one have a totally different url. Nothing worked. I feel like I'm probably just doing something wrong, so I'll keep testing.
It does, however, work on other sites, such as jstor.org
Autofill doesn't seem to be working at all on that website, because we're not detecting the username field. That's fairly easily fixable, but it doesn't seem to really match what you described either - are you seeing something being filled in the password field?
Schoolology works for me now with the fix from 2dc609cc8652e1aba7f31b04fef70b67c6eea023 (with multiple logins).