Last active
January 18, 2019 14:02
-
-
Save dimitrisdovinos/474aceaf47405d29911e859493e83e1d to your computer and use it in GitHub Desktop.
Javascript for getting the authorization code from Cognito
This file contains 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
const axios = require('axios'); | |
const debug = require('debug')('auth'); | |
const config = require('../../config'); | |
const qs = require('qs'); | |
async function awsCallTokenEndpoint(grantType, accessToken) { | |
const data = { | |
grant_type: grantType, | |
client_id: config.cognito.clientId, | |
code: accessToken, | |
scope: 'profile', | |
redirect_uri: config.cognito.redirectCallback, | |
}; | |
const p = { | |
method: 'post', | |
url: `${config.cognito.domainUrl}/oauth2/token`, | |
data: qs.stringify(data), | |
auth: { | |
username: config.cognito.clientId, | |
password: config.cognito.secret, | |
}, | |
}; | |
debug(`AWS oauth2/token request parameters: ${JSON.stringify(p)}`); | |
const awsResponse = await axios(p); | |
debug(`AWS oauth2/token response : ${JSON.stringify(awsResponse.data)}`); | |
return awsResponse; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment