Skip to content

Instantly share code, notes, and snippets.

@roxeteer
Last active November 25, 2018 08:30
Show Gist options
  • Save roxeteer/ed2d6309c9ccca7afb2ec482fef9e903 to your computer and use it in GitHub Desktop.
Save roxeteer/ed2d6309c9ccca7afb2ec482fef9e903 to your computer and use it in GitHub Desktop.
const got = require('got');
const querystring = require('querystring');
async function getGhostToken() {
const { GHOST_NAME, GHOST_USER, GHOST_PASS, GHOST_CLIENT_ID, GHOST_CLIENT_SECRET } = process.env;
const headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
const body = querystring.stringify({
grant_type: 'password',
username: GHOST_USER,
password: GHOST_PASS,
client_id: GHOST_CLIENT_ID,
client_secret: GHOST_CLIENT_SECRET
});
let result;
try {
result = await got.post(
`https://${GHOST_NAME}.ghost.io/ghost/api/v0.1/authentication/token`,
{ headers, body }
).on('error', (err) => {
console.error(err);
throw new Error(err.message);
});
} catch (e) {
throw e;
}
return JSON.parse(result.body);
}
module.exports = {
getGhostToken
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment