Jump to content

Resource Owner Password Grant "must be a POST request"


Recommended Posts

Hi all,

I've been trying to get a login working using the Resource Owner Password Grant oAuth, however I can't seem to make it work.

Here's my request:

const form = {
  'grant_type': 'password',
  'username': 'username',
  'password': 'pass',
  'scope': 'profile',
  'client_id': 'client_id',
}
  var formBody = [];
  for (var property in form) {
    var encodedKey = encodeURIComponent(property);
    var encodedValue = encodeURIComponent(form[property]);
    formBody.push(encodedKey + "=" + encodedValue);
  }
  formBody = formBody.join("&");
  await fetch(`https://example.com/oauth/token`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    body: formBody
  })

All I get back is an error:

{
    "error": "invalid_request",
    "error_description": "request must be a POST request"
}

Did I format this the wrong way or am I missing something? I've been following the oAuth docs but maybe I'm missing something. Any help would be appreciated!

Edited by creativiii
Link to comment
Share on other sites

2 hours ago, bfarber said:

If you monitor the HTTP request, is there a redirect occurring by chance, perhaps adding a trailing slash to /token or something?

Turns out the problem was the missing trailing slash, just got confused by the errors and thought it was something else.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...