Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't asign content-type on POST #58

Open
megamauricio009 opened this issue Jun 20, 2017 · 0 comments
Open

Can't asign content-type on POST #58

megamauricio009 opened this issue Jun 20, 2017 · 0 comments

Comments

@megamauricio009
Copy link

Hi guys i'm trying to get a token from a service but it said's "error":"invalid_request","error_description":"Missing grant type
i was searching about this error and the solution is changing the content-type to "application/x-www-form-urlencoded" cause it can be sended by JSON. but it doesn't work, my code is this

`
var json = JSON.parse(JSON.stringify(jsonResp))

var body = decryptBody(req.body);
body = body.replace(/\0/g, '')
body = JSON.parse(body)
var auth = {grant_type:"password", username: "pass" , password: "usr" }
if(!isValidProtocol(body)){
//console.log(body)
json.error = true,
json.desc = 'invalid protocol'
res.statusCode = 202;
res.json(encryptBody(json));
}

requestify.request( "http://localhost:7070" + '/oauth/token',{
method: "POST",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
dataType: 'form-url-encoded',
auth: auth
})
.then(function(response) {
json.data = response.getBody();
res.json(encryptBody(json));
}).catch(function(err){
console.log('ERROR:')
console.log(err)
//console.log(body.data)
console.log(auth)
json.error = true,
json.desc = 'invalid login params'
res.statusCode = 202;
res.json(encryptBody(json));
});`

and the result

ERROR: Response { code: 400, headers: { 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'cache-control': 'no-cache, no-store, max-age=0, must-revalidate', pragma: 'no-cache', expires: '0', 'x-frame-options': 'DENY', 'content-type': 'application/json;charset=UTF-8', 'transfer-encoding': 'chunked', date: 'Tue, 20 Jun 2017 19:31:43 GMT', connection: 'close' }, body: '{"error":"invalid_request","error_description":"Missing grant type"}' }
Waitng for the answer, THANK YOU..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant