Skip to content

Instantly share code, notes, and snippets.

@jakebloom
Last active March 27, 2020 18:46
Show Gist options
  • Save jakebloom/fc10b947ee8b29a71d2f51fe14016ca0 to your computer and use it in GitHub Desktop.
Save jakebloom/fc10b947ee8b29a71d2f51fe14016ca0 to your computer and use it in GitHub Desktop.
const jwt_simple = require('jwt-simple');
const fetch = require('node-fetch');
const qs = require('query-string');
const JWT_BEARER_URI = 'urn:ietf:params:oauth:grant-type:jwt-bearer';
const WELKIN_ENDPOINT_URL = 'https://api.welkinhealth.com/v1/token';
async function getToken() {
const tokenData = {
'iss': CLIENT_ID,
'aud': WELKIN_ENDPOINT_URL,
'exp': Math.round(new Date() / 1000) + 3600,
'scope': 'all',
};
const token = jwt_simple.encode(tokenData, CLIENT_SECRET, 'HS256');
const res = await fetch(WELKIN_ENDPOINT_URL, {
method: 'POST',
body: qs.stringify({
assertion: token,
grant_type: JWT_BEARER_URI,
}),
});
const j = await res.json();
console.log(j);
}
getToken().then(() => console.log('done'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment