creativiii Posted April 25, 2020 Posted April 25, 2020 (edited) 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, 2020 by creativiii
bfarber Posted April 27, 2020 Posted April 27, 2020 If you monitor the HTTP request, is there a redirect occurring by chance, perhaps adding a trailing slash to /token or something?
creativiii Posted April 27, 2020 Author Posted April 27, 2020 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.
Recommended Posts