been given an API endpoint from one of the backend devs to get back a token to use for future API calls but I'm having issues with the grant_type.
I've been given a username and password and been told to set the grant_type as 'password'.
I'm using Axios, this is was first attempt at getting this to work:
const data = {
Username: 'Test',
Password: 'TestPassword',
grant_type: 'password'
};
const config = {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
};
axios.post('https://example.com/api/token', data, config)
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});
This returns an error (400) of unsupported grant type.
Reading up online, someone recommended using the QS package to stringify the data:
const creds = qs.stringify({
Username: 'Test',
Password: 'TestPassword',
grant_type: 'password'
});
This however gives me CORS problems (oddly). By this, I mean using the stringify method I get CORS, but don't get CORS errors without it.
How should grant_type be passed into the Axios post?
Is there a correct way to pass the grant_type via fetch or Axios?