I'm working with an auth provider where I first have to do a post to get a users ID. I then take that and do a get against another URL to get their roles.This is my first time using Axios and I'm having trouble returning the data I get.In this code, mgmtRes contains the data. But i can't seem to return it back up the chain to the calling applicaiton.For instance, if I use postman it will just spin and nothing is returned.I feel like there's some fundamental understanding I'm missing here and I'd appreciate the help.const axios = require('axios'); var authUrl ='https://---------------/oauth/token'; var authHeaders = { "client_id" : "-----------------", "client_secret":"---------------------", "audience":"https://--------------/api/v2/", "grant_type":"client_credentials" } exports.getUserMgmtData = (req, res) => { axios.post(authUrl, authHeaders) .then((authResponse) => { var mgmtHeaders = { headers: { "Authorization": `Bearer ${authResponse.data.access_token}`, 'Content-Type': 'application/json', } } dataurl = `https://--------------------/api/v2/users/${req.params['id']}` axios.get(dataurl, mgmtHeaders) .then((mgmtRes) => { // This is the valid data. return mgmtRes; }) .catch(function(err) { console.log("Mgmt Error: " + err); }); }).catch(function(err) { console.log("Auth Error: " + err); }); }
Submitted November 16, 2019 at 04:53PM by 6ThePrisoner
No comments:
Post a Comment