Skip to content

Commit

Permalink
removing extra whitespace and using promises
Browse files Browse the repository at this point in the history
  • Loading branch information
cortl committed Aug 13, 2019
1 parent 81cbb07 commit a4fc896
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,23 @@ module.exports.templateTags = [{
}],
async run(_context, target_audience, location) {
const serviceCredentials = JSON.parse(fs.readFileSync(location));

const payload = {
iat: Math.floor(new Date().getTime() / 1000) - 10,
exp: Math.floor(new Date().getTime() / 1000) + 120,
target_audience
}

const options = {
algorithm: "RS256",
keyid: serviceCredentials.private_key_id,
audience: tokenUrl,
issuer: serviceCredentials.client_email,
subject: serviceCredentials.client_email,
}

const token = jwt.sign(payload, serviceCredentials.private_key, options);

const formData = new FormData();
formData.append('assertion', token);
formData.append('grant_type', 'urn:ietf:params:oauth:grant-type:jwt-bearer');

const res = await axios.post(tokenUrl, formData, axiosConfig);

return res.data.id_token;
return await axios.post(tokenUrl, formData, axiosConfig).then(res => res.data.id_token);
}
}];

0 comments on commit a4fc896

Please sign in to comment.