goodreads-api-node
goodreads-api-node copied to clipboard
Export methods to save oauth tokens between sessions
I'd like to use this library from a backup script, where I can't approve OAuth access each time.
I've added two methods (setAccessToken
and dumpAccessToken
) to auth once and save the access token.
I use 'em like this:
const gr = goodreads({
key: settings.GOODREADS_APP_KEY,
secret: settings.GOODREADS_APP_SECRET
});
gr.initOAuth();
const oauthUrl = await gr.getRequestToken();
console.log(`open ${oauthUrl}`);
console.log(`then press any key to continue`);
await new Promise(resolve => process.stdin.once('data', resolve));
await gr.getAccessToken();
console.log(gr.dumpAccessToken());
Then in future non-interactive runs:
const gr = goodreads({
key: settings.GOODREADS_APP_KEY,
secret: settings.GOODREADS_APP_SECRET
});
gr.initOAuth();
gr.setAccessToken({
token: settings.GOODREADS_OAUTH_TOKEN,
secret: settings.GOODREADS_OAUTH_SECRET
});
+1 to this PR! I have a similar change on my fork, serving the same purpose (saving tokens between sessions).
+1 for this
Sorry, took me a while. I'm fine with merging this. Could you resolve the conflicts?
@hurrymaplelad Can we get the conflicts resolved? so @baahrens can merge :)