Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object # has no method 'getOAuthAccessToken' #42

Closed
shamod opened this issue May 8, 2011 · 8 comments
Closed

Object # has no method 'getOAuthAccessToken' #42

shamod opened this issue May 8, 2011 · 8 comments

Comments

@shamod
Copy link

shamod commented May 8, 2011

I keep getting the error above on callback.

Any idea why?

@ciaranj
Copy link
Owner

ciaranj commented May 8, 2011

I think its probably related to: #39 .. ARe you using express 2 ?

@shamod
Copy link
Author

shamod commented May 9, 2011

i tried updating to express 2. still the same issue.

On Sun, May 8, 2011 at 3:24 AM, ciaranj <
reply@reply.github.com>wrote:

I think its probably related to:
#39 .. ARe you using express 2
?

Reply to this email directly or view it on GitHub:
#42 (comment)

@ciaranj
Copy link
Owner

ciaranj commented May 9, 2011

Ah sorry I was concerned that you might be (i.e. that could be what was causing the issue!) Can you put your code somewhere ?

@shamod
Copy link
Author

shamod commented May 10, 2011

I have two files: app.js and oauth_controller.js

it works fine while retrieving the request toke and secret.

it fails when trying to call getOAuthAccessToken from app.js by calling oauthController.getOAuthTokenAndSecret.

thanks for your kind help.

*** app.js:

var express = require('express');

var app = module.exports = express.createServer();

var memStore = require('connect').session.MemoryStore;

var oauthController = require('./controllers/oauth_controller');

// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));
app.use(express.static(__dirname + '/public'));
app.use(express.cookieParser());
app.use(express.session({secret: 'secret', store: memStore({
reapInterval: 60000 * 10
})}));
app.use(app.router);
});

app.get('/user/new', function(req, res) {
oauthController.getRequestTokenForAuhtorization(function(error, oa, request_token, request_token_secret, url) {
if(error) {
sys.log(JSON.stringify(error));
} else {
req.session.oa = oa;
req.session.request_token = request_token;
req.session.request_token_secret = request_token_secret;
res.render('user/new', {locals: {
user: req.body && req.body.user,
twitterUrl: url
}
});
}
});
});

app.get('/user/oauth', function(req, res) {
if(req.session.request_token) {

*** Fails here --> oauthController.getOAuthTokenAndSecret(req.session.oa, 
                       req.session.request_token, 
                       req.session.request_token_secret, 
                       req.param('oauth_verifier'),
                       function(error, oauth_access_token, oauth_access_token_secret) {
                         if(error) {
            sys.log(JSON.stringify(error));
                         } else {
                           res.render('user/new', {locals: {
                 user: req.body && req.body.user
                }
                   });
                         }
                       }
                     );
} else {
  sys.log('callback oauth url error');
}

});

*** oauth_controller.js:

var OAuth = require('oauth').OAuth;
var sys = require('sys');

exports.getRequestTokenForAuhtorization = function(callback) {

var consumer_key = some_key,
consumer_secret = some_secret,
request_token_url = 'https://api.twitter.com/oauth/request_token',
access_token_url = 'https://api.twitter.com/oauth/access_token',
authorize_url = 'https://api.twitter.com/oauth/authorize?oauth_token=',
oauth_version = '1.0',
callback_url = 'http://localhost:3000/user/oauth',
encryption_type = 'HMAC-SHA1';

var oa = new OAuth(request_token_url, access_token_url, consumer_key, consumer_secret,
oauth_version, callback_url, encryption_type);

oa.getOAuthRequestToken(function(error, request_token, request_token_secret, results) {
if(error) {
callback(error, null, null, null, null);
} else {
var url = authorize_url + request_token;
callback(null, oa, request_token, request_token_secret, url);
}
});
};

exports.getOAuthTokenAndSecret = function(oa, request_token, request_token_secret, oauth_verifier, callback) {
oa.getOAuthAccessToken(request_token, request_token_secret, oauth_verifier,
function(error, oauth_access_token, oauth_access_token_secret, results) {
if(error) {
callback(error, null, null);
} else {
sys.log("oauth_access_token: " + oauth_access_token);
sys.log("oauth_access_token_secret: " + oauth_access_token_secret);
callback(null, oauth_access_token, oauth_access_token_secret);
}
}
);
};

@shamod shamod closed this as completed May 10, 2011
@shamod shamod reopened this May 10, 2011
@ciaranj
Copy link
Owner

ciaranj commented May 10, 2011

Hmmm I've only just noticed which project this issue is against, have you seen http://github.com/ciaranj/connect-auth I've got a (working!) implementation of a Twitter authentication system in there, that would almost certainly be a good place to look for clues (if not used!)

@ciaranj
Copy link
Owner

ciaranj commented May 10, 2011

When you inspect the 'oauthController' (console.log) what methods are on that object. I don't think this is a node-oauth issue, more an express thing ... strange.

@shamod
Copy link
Author

shamod commented May 21, 2011

when i inspect oauthController, i see all methods in there. it is really this method that fails

oa.getOAuthAccessToken(request_token, request_token_secret, oauth_verifier,
function(error, oauth_access_token, oauth_access_token_secret, results)

wierd thing is oa.getOAuthRequestToken works with no issue but not oa.getOAuthAccessToken.

how is this possible? after it fails at oa.getOAuthAccessToken, one thing to notice is that we get error router/index.js file in express. could it be that the callback url has issue with express?

@ciaranj
Copy link
Owner

ciaranj commented Jul 29, 2011

Is this still an issue for you ?

@ciaranj ciaranj closed this as completed Aug 6, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants