Guest User

Untitled

a guest
Jan 19th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. const axios = require('axios');
  2. const debug = require('debug')('auth');
  3. const config = require('../../config');
  4. const qs = require('qs');
  5.  
  6. async function awsCallTokenEndpoint(grantType, accessToken) {
  7. const data = {
  8. grant_type: grantType,
  9. client_id: config.cognito.clientId,
  10. code: accessToken,
  11. scope: 'profile',
  12. redirect_uri: config.cognito.redirectCallback,
  13. };
  14.  
  15. const p = {
  16. method: 'post',
  17. url: `${config.cognito.domainUrl}/oauth2/token`,
  18. data: qs.stringify(data),
  19.  
  20. auth: {
  21. username: config.cognito.clientId,
  22. password: config.cognito.secret,
  23. },
  24. };
  25. debug(`AWS oauth2/token request parameters: ${JSON.stringify(p)}`);
  26. const awsResponse = await axios(p);
  27. debug(`AWS oauth2/token response : ${JSON.stringify(awsResponse.data)}`);
  28.  
  29. return awsResponse;
  30. }
Add Comment
Please, Sign In to add comment