Created
October 28, 2019 11:56
-
-
Save jonurry/0c318b60b24bed7b0dc194d102e0afc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function (input) { | |
console.log(`INSIDE #generic_request: ${JSON.stringify(input)}`); | |
const { client_id, client_secret, code, refresh_token } = input.body; | |
console.log( | |
`PARAMS FOR getAccessToken: ${JSON.stringify({ | |
client_id, | |
client_secret, | |
code, | |
})}`, | |
); | |
const accessTokenInput = { | |
client_id, | |
client_secret, | |
code, | |
}; | |
let accessTokenResponse = {}; | |
let refreshTokenResponse = {}; | |
console.log( | |
`CALLING getAccessToken WITH: ${JSON.stringify(accessTokenInput)}`, | |
); | |
try { | |
accessTokenResponse = await falafel.gotowebinar.getAccessToken( | |
accessTokenInput, | |
); | |
} catch (tokenError) { | |
console.log( | |
`ERROR WHEN CALLING getAccessToken: ${JSON.stringify(tokenError)}`, | |
); | |
if (tokenError.response.statusCode === 401) { | |
try { | |
refreshTokenResponse = await falafel.gotowebinar.refreshAccessToken( | |
...accessTokenInput, | |
refresh_token, | |
); | |
} catch (refreshTokenError) { | |
console.log( | |
`ERROR WHEN CALLING refreshAccessToken: ${JSON.stringify( | |
refreshTokenError, | |
)}`, | |
); | |
} | |
} | |
} | |
console.log( | |
`ACCESS TOKEN RESPONSE: ${JSON.stringify(accessTokenResponse)}`, | |
); | |
console.log( | |
`REFRESH TOKEN RESPONSE: ${JSON.stringify(refreshTokenResponse)}`, | |
); | |
return { | |
status_code: 200, | |
headers: {}, | |
body: { | |
access_token: 'vAfOZToGIW9XNYkOEGCBwWmBW8e9', | |
token_type: 'Bearer', | |
refresh_token: '3Ge2ReRwTDIfDi7NGlMgJOjJyYxBLOrl', | |
expires_in: 3600, | |
account_key: '2097362797512405510', | |
account_type: '', | |
email: '[email protected]', | |
firstName: 'Barry', | |
lastName: 'Jenkins', | |
organizer_key: '347702247648928518', | |
version: '3', | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment