in src/index.ts [79:105]
_fetchTokensFromCode(redirectURI, code) {
const authorization = this._userPoolAppSecret && Buffer.from(`${this._userPoolAppId}:${this._userPoolAppSecret}`).toString('base64');
const request = {
url: `https://${this._userPoolDomain}/oauth2/token`,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
...(authorization && {'Authorization': `Basic ${authorization}`}),
},
data: stringify({
client_id: this._userPoolAppId,
code: code,
grant_type: 'authorization_code',
redirect_uri: redirectURI,
}),
} as const;
this._logger.debug({ msg: 'Fetching tokens from grant code...', request, code });
return axios.request(request)
.then(resp => {
this._logger.debug({ msg: 'Fetched tokens', tokens: resp.data });
return resp.data;
})
.catch(err => {
this._logger.error({ msg: 'Unable to fetch tokens from grant code', request, code });
throw err;
});
}