Open user1702 opened 10 years ago
I'm wondering the same thing. Any luck?
Try this in getOAuthAccessToken:
{
'grant_type': 'password',
username: {username},
password: {password}
}
This worked for me.
I have a question about this method. Doesn't the function 'getOAuthAccessToken' require a 'code' param, which is not used in the Resource Owner Password flow? How do we handle this param?
@arryon You can just pass ''
as first argument for getOAuthAccessToken
Something like this:
oauth2.getOAuthAccessToken(
'',
{
'grant_type': 'password',
'username': <userName>,
'password': <passWord>
},
function (e, access_token, refresh_token, results) {
console.log('bearer: ',access_token);
someCallback();
})
Is it possible to configure {'grant_type':'password'} in node-oauth? var OAuth2 = OAuth.OAuth2;
var twitterConsumerKey = 'your key'; var twitterConsumerSecret = 'your secret'; var oauth2 = new OAuth2( twitterconsumerKey, twitterConsumerSecret, 'https://api.twitter.com/', null, 'oauth2/token', null); oauth2.getOAuthAccessToken( '', {'grant_type':'client_credentials'}, function (e, access_token, refresh_token, results){ console.log('bearer: ',access_token); oauth2.get('protected url', access_token, function(e,data,res) { if (e) return callback(e, null); if (res.statusCode!=200) return callback(new Error( 'OAuth2 request failed: '+ res.statusCode),null); try { data = JSON.parse(data);
} catch (e){ return callback(e, null); } return callback(e, data); }); });