curl succeeds with oath2 but fails with node.js request -
the following curl request works properly, returning authentication token should
curl post -s -d "grant_type=password&username=someusername&password=somepassword&client_id=someid&client_secret=somesecret&response_type=token" "someurl"
when equivalent request in node.js fails
let url = someurl var datastring = 'grant_type=password&username=somename&password=somepassword&client_id=someid&client_secret=somesecret&response_type=token'; var options = { url: url, method: 'post', body: datastring, allow_redirects : true }; function callback(error, response, body) { if (!error && response.statuscode == 200) { console.log(body); } console.log(error) console.log(body) } request(options, callback);
the error is
{"error":"unauthorized","error_description":"an authentication object not found in securitycontext"}
which may specific code. @ rate, differences (in default parameters presumably or configuration) explain difference. note, programs fails both , without allow_redirects option, redirection should allowed.
this node v7.10.0 running on macosx , request 2.81.0
my first assumption you're missing headers required request
let url = someurl var datastring = 'grant_type=password&username=somename&password=somepassword&client_id=someid&client_secret=somesecret&response_type=token'; var options = { url: url, method: 'post', body: datastring, headers: { 'content-type': 'application/x-www-form-urlencoded' }, allow_redirects: true }; function callback(error, response, body) { if (!error && response.statuscode == 200) { console.log(body); } console.log(error) console.log(body) } request(options, callback);
if isn't correct, let me know , i'll resolve answer
Comments
Post a Comment