Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ims.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,15 @@ async function _toTokenResult (apiResponse) {
*
* @param {string} token The token to decode and extract the token value from
* @returns {object} The decoded token payload data without header and signature
* @throws {Error} If the token is invalid or cannot be decoded
*/
function getTokenData (token) {
const [, payload] = token.split('.', 3)
return JSON.parse(Buffer.from(payload, 'base64'))
const base64 = payload.replace(/-/g, '+').replace(/_/g, '/')
// add padding if necessary
const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4)
const decoded = Buffer.from(padded, 'base64').toString('utf-8')
return JSON.parse(decoded)
}

/**
Expand Down