Advertisement
Guest User

Untitled

a guest
May 10th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. // Set the configuration settings
  2. const credentials = {
  3. client: {
  4. id: config.vigipay.oauth.client_id,
  5. secret: config.vigipay.oauth.client_secret
  6. },
  7. auth: {
  8. tokenHost: 'http://ebipssso.test.vggdev.com/core',
  9. tokenPath: '/connect/token',
  10. authorizePath: '/connect/authorize'
  11. }
  12. };
  13.  
  14. // Initialize the OAuth2 Library
  15. const oauth2 = require('simple-oauth2').create(credentials);
  16.  
  17.  
  18. function getAccessToken(param, callback) {
  19. const tokenConfig = {
  20. username: config.vigipay.credentials.username,
  21. password: config.vigipay.credentials.password
  22. };
  23. oauth2.ownerPassword
  24. .getToken(tokenConfig)
  25. .then((result) => {
  26. const token = oauth2.accessToken.create(result);
  27. console.info('Access Token', token);
  28. callback(responseHandler(201, 'Access token received', result));
  29. })
  30. .catch((err) => {
  31. console.error('Get Access Token Error', err);
  32. if(err.status && err.message){
  33. callback(responseHandler(err.status, err.message, err));
  34. }else
  35. callback(responseHandler(500, 'Error received', err));
  36. });
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement