Problem with fetch on OAuth

hi, i am trying to login through OAuth using API with fetch, I have make sure that Content Type is application/x-www-form-urlencoded, the response returns False with an error : {“error”:“unsupported_grant_type”} I tested it in postman and it works just fine!

Here is My Code:

fetch('http://192.168.98.219/API/Token',{ method: 'POST', headers: { "Content-type": "application/x-www-form-urlencoded" }, body:JSON.stringify({ grant_type:'password', Username:"agent1@live.com", Password:"123456" }) }) .then(function(response) { console.log("Body Text:"+response._bodyText); console.log(JSON.stringify(response)); }) .catch(function(err) { console.log("Fetch error: " + err); });
Please help !!

This has to do with your backend configuration. See this other forum post about a similar issue.

Perhaps you could try to move the grant_type property to the headers object in your fetch request?

If that doesn’t help, you’ll need to adjust how you authenticate against your backend. Sending a username and password in plain text (even over HTTPS) is not a good practice anyway.