diff --git a/lib/oauth2.js b/lib/oauth2.js index 77241c43..17a32d1e 100644 --- a/lib/oauth2.js +++ b/lib/oauth2.js @@ -181,10 +181,11 @@ exports.OAuth2.prototype.getOAuthAccessToken= function(code, params, callback) { var codeParam = (params.grant_type === 'refresh_token') ? 'refresh_token' : 'code'; params[codeParam]= code; - var post_data= querystring.stringify( params ); - var post_headers= { - 'Content-Type': 'application/x-www-form-urlencoded' - }; + var post_data = querystring.stringify(params); + var post_headers = { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Accept': 'application/json' + }; this._request("POST", this._getAccessTokenUrl(), post_headers, post_data, null, function(error, data, response) { @@ -192,15 +193,9 @@ exports.OAuth2.prototype.getOAuthAccessToken= function(code, params, callback) { else { var results; try { - // As of http://tools.ietf.org/html/draft-ietf-oauth-v2-07 - // responses should be in JSON results= JSON.parse( data ); } catch(e) { - // .... However both Facebook + Github currently use rev05 of the spec - // and neither seem to specify a content-type correctly in their response headers :( - // clients of these services will suffer a *minor* performance cost of the exception - // being thrown results= querystring.parse( data ); } var access_token= results["access_token"];