ciaranj / node-oauth

OAuth wrapper for node.js
MIT License
2.44k stars 662 forks source link

OAuth2 Resource Owner Password Credentials flow #181

Open user1702 opened 10 years ago

user1702 commented 10 years ago

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); }); });

coolaj86 commented 10 years ago

I'm wondering the same thing. Any luck?

dchem commented 9 years ago

Try this in getOAuthAccessToken:

{
  'grant_type': 'password',
  username: {username},
  password: {password}
}

This worked for me.

arryon commented 8 years ago

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?

dchem commented 8 years ago

@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();
     })