
Vue/Axios get bearer token into variable after posting clint_crd
- or -
Post a project like this1395
£30(approx. $40)
- Posted:
- Proposals: 3
- Remote
- #3301792
- Awarded
Description
Experience Level: Entry
I have an application I'm trying to integrate with using VUE and AXIOS.
The application requires client credentials to be posted which will then return a bearer token.
I'm massively struggling to get the bearer token out of the AXIOS request and into a variable I can then use on the next request before then using it to log out.
I have got as far as the below, however I seem to be tripping my at the point of these lovely promises and async / sync request types :-(
I'm after example code in which will allow me to do something simular to:
var _Token = Login();
RequestProjectData(_Token,ID);
Logout(_Token);
Where I got to, which is probably miles off...
export function Login() {
var qs = require('qs');
var data = qs.stringify({
'client_id': 'CLIENTID...Fhduiosji43298.api',
'client_secret': 'SCREThgfgy798435y89roi.dfdesghiu',
'grant_type': 'client_credentials'
});
var config = {
method: 'post',
url: 'https://SERVER:444/WebService/Api/logon',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: data
};
const request = axios(config)
.then(function (response) {
//console.log(JSON.stringify(response.data.access_token));
return response.data;
})
.catch(function (error) {
console.log(error.response);
});
return {
payload: request
};
//return result
}
Thanks in advance
The application requires client credentials to be posted which will then return a bearer token.
I'm massively struggling to get the bearer token out of the AXIOS request and into a variable I can then use on the next request before then using it to log out.
I have got as far as the below, however I seem to be tripping my at the point of these lovely promises and async / sync request types :-(
I'm after example code in which will allow me to do something simular to:
var _Token = Login();
RequestProjectData(_Token,ID);
Logout(_Token);
Where I got to, which is probably miles off...
export function Login() {
var qs = require('qs');
var data = qs.stringify({
'client_id': 'CLIENTID...Fhduiosji43298.api',
'client_secret': 'SCREThgfgy798435y89roi.dfdesghiu',
'grant_type': 'client_credentials'
});
var config = {
method: 'post',
url: 'https://SERVER:444/WebService/Api/logon',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: data
};
const request = axios(config)
.then(function (response) {
//console.log(JSON.stringify(response.data.access_token));
return response.data;
})
.catch(function (error) {
console.log(error.response);
});
return {
payload: request
};
//return result
}
Thanks in advance

Andrew P.
100% (5)Projects Completed
5
Freelancers worked with
4
Projects awarded
83%
Last project
10 Jun 2021
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies