OAuth2 Resource Owner Password Credentials flow #181

Open
user1702 opened this Issue Feb 14, 2014 · 4 comments

Projects

None yet

4 participants

@user1702

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

Contributor
coolaj86 commented Oct 7, 2014

I'm wondering the same thing. Any luck?

dchem commented May 27, 2015

Try this in getOAuthAccessToken:

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

This worked for me.

arryon commented Oct 15, 2016

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 Oct 17, 2016

@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();
     })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment