I'm trying to call endpoint to generate access token using oauth in django it is working when I call the endpoint using jquery but not working when I try to call it with fetch
here is the code for fetch
fetch(`https://<domain>/o/token/`, {
method: 'POST',
body:{
grant_type:'password',
client_id: "<client-id>",
client_secret:"<client-secret>",
username:"<username>",
password:"<password>"
}
})
.then(res => res.json())
.then(res => {console.log(res)});
the output is
{error: 'unsupported_grant_type'}
while when I'm calling it using jquery ajax as below its working
$.post({
url:'https://<domain>/o/token/',
data:{
grant_type:'password',
client_id: "<client-id>",
client_secret:"<client-secret>",
username:"<username>",
password:"<password>"
},
success: function(data){
console.log(data);
}
})
the output is
{access_token: '<access-token>', expires_in: 3600, token_type: 'Bearer', scope: 'read write groups', refresh_token: '<refresh-token>'}