This code works in other situations but I think the setup of the file is what is causing the issue and I’m not sure how to get around it. It’s a contract job so I don’t have the ability to change the setup of the fil and I’m not sure how to fix this error.
I’m calling the OAuth module from here:
var common = require('common');
var OAuth2 = require('oauth2');
var google = require('google');
exports.init = function(app) {
app.get('/oauth/google', function(req, res) {
var gmailAuthObject =
new OAuth2(google.clientId,
google.clientSecret,
'',
'https://accounts.google.com/o/oauth2/auth',
'https://accounts.google.com/o/oauth2/token');
var redirectUrl = gmailAuthObject.getAuthorizeUrl(
{ redirect_uri:google.callbackRedirect,
scope:'https://www.google.com/m8/feeds',
response_type:'code',
access_type:'offline' });
res.redirect(redirectUrl);
});
app.get('/oauth/google/callback', function(req, res) {
var code = req.query.code;
var content = '<script>' +
'window.opener.SITENAME.setGoogleCode("' + code + '");' +
'window.close();' +
'</script>';
res.writeHeader(200, {"Content-Type": "text/html"});
res.end(content, 'utf-8');
});
// Other Networks...
/******************************************************************************/
};
It’s failing at new OAuth2 with: CALL_NON_FUNCTION_AS_CONSTRUCTOR (native)
The OAuth module as exports on each function like exports.OAuth2.
I’m guessing the issue is because it’s inside exports.init but I can’t fix it. Any ideas or help here? Thanks!
If you are using this module, it seems that you should do (on the second line of your supplied code):