Posted April 25, 20205 yr 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 April 25, 20205 yr by creativiii
April 27, 20205 yr If you monitor the HTTP request, is there a redirect occurring by chance, perhaps adding a trailing slash to /token or something?
April 27, 20205 yr Author 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.
Archived
This topic is now archived and is closed to further replies.