From a4fc89613980cb2bb033469b9c109d0c7b9c2dcb Mon Sep 17 00:00:00 2001 From: cortl Date: Tue, 13 Aug 2019 14:34:19 -0500 Subject: [PATCH] removing extra whitespace and using promises --- plugin.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/plugin.js b/plugin.js index 7ed1bee..fa0b807 100644 --- a/plugin.js +++ b/plugin.js @@ -23,13 +23,11 @@ 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, @@ -37,15 +35,11 @@ module.exports.templateTags = [{ 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); } }];