jetlej
1
I’m using Meteor’s built in HTTP.post to send an authorization code to the Google OAuth2 API to get a token back.
However I’m getting the error: Required parameter is missing: grant_type. Guessing it’s an encoding issue?
HTTP.post('https://accounts.google.com/o/oauth2/token', {data: {
code: 'XXXXXXXXXXX',
client_id : 'XXXXXXX.apps.googleusercontent.com',
client_secret: 'XXXXXXXXXXXXXXXXXXXXXXX',
grant_type : 'authorization_code'
}}, function(error, response ){
if ( error ) {
console.log( error );
} else {
console.log( response );
}
});
It should be
HTTP.post('https://accounts.google.com/o/oauth2/token', {params: {
code: 'XXXXXXXXXXX',
client_id : 'XXXXXXX.apps.googleusercontent.com',
client_secret: 'XXXXXXXXXXXXXXXXXXXXXXX',
grant_type : 'authorization_code'
}}, function(error, response ){
if ( error ) {
console.log( error );
} else {
console.log( response );
}
});
BTW, I hope you’re doing this on the server - you don’t want to expose your client secret on the browser!
1 Like
jetlej
3
That worked! Thanks @robfallows.
I also want to note for anyone finding this that HTTP runs asynchronously if you include a callback function.
1 Like