Hi all, I’m currently trying to develop a command-line tool that interacts with blockstack storage, but I’m hitting a bit of a wall trying to authenticate the user. Because the blockstack.js npm library assumes you’re calling its methods from the context of a rendered website, it tries to make calls to the window
object but because I’m not launching a window it fails because window is not defined. I’ve tried using the puppeteer headless browser and importing blockstack through a page.addScriptTag
call and then calling the signin through blockstack.redirectToSignIn
but it just crashes saying Target closed.
I suspect it fails because blockstack is trying to redirect to a blockstack://
link which puppeteer doesn’t know how to handle so it just crashes. Does anybody have any ideas of how to work around this?
If I recall correctly there was a discussion some time ago about getting blockstack.js
to work on a node program but I can’t find it currently.
This definitely needs to be a feature though. If you want to see how to log-in via recovery phrase you can look at my code, but if you want to authenticate with the Blockstack Browser then yeah, you’ll need to host a (local) webserver and launch an auth request in the browser to get your app key, which is through blockstack://{}
or blockstack.org/auth?auth={}
url request and have it redirect to your server.
Have you tried to use the (os default) browser instead of a headless one so it can interact properly with the blockstack browser?
I haven’t tried using the os default browser, although puppeteer runs on chrome, but wouldn’t that also require the user to leave that browser window open given that the auth is all client side?
If it’s the OS default browser (or whatever the end-user uses to auth) then it will either redirect to https://browser.blockstack.org
or to the localhost://8000
in order to auth from whichever browser they use, afaik. I’m not sure if the wrapped-headless one can do that, but it doesn’t seem like it from your experience.
Though blockstack.js
won’t do that, so you’ll have to do it manually by replicating code, most likely… not fun but gotta do what you gotta do.
Blockstack has a CLI that lets you interact with storage:
it def requires the user to leave the browser window, as the puppeteer runs on chrome