Search code examples
node.jsangularjstwitterexpresseveryauth

Configuring Twitter everyauth `consumerKey` for node angular express bootstrap web app


I'm using https://github.com/ganarajpr/express-angular and get this error when I try running the app:

git clone https://github.com/ganarajpr/express-angular.git && cd express-angular/ && npm install && nodemon app.js

$ nodemon app.js 
26 Oct 09:55:31 - [nodemon] v0.7.10
26 Oct 09:55:31 - [nodemon] to restart at any time, enter `rs`
26 Oct 09:55:31 - [nodemon] watching: /Users/qihanzhang/git/express-angular
26 Oct 09:55:31 - [nodemon] starting `node app.js`
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0

/Users/qihanzhang/git/express-angular/node_modules/everyauth/lib/modules/everymodule.js:133
      throw new Error(debugMsg);
            ^
Error: WARNING: You are trying to access the attribute/method configured by `consumerKey`, which you did not configure. Time to configure it.
    at EveryModule.(anonymous function) [as consumerKey] (/Users/qihanzhang/git/express-angular/node_modules/everyauth/lib/modules/everymodule.js:133:13)
    at EveryModule.<anonymous> (/Users/qihanzhang/git/express-angular/node_modules/everyauth/lib/modules/oauth.js:27:14)
    at EveryModule.init (/Users/qihanzhang/git/express-angular/node_modules/everyauth/lib/modules/everymodule.js:77:8)
    at EveryModule.routeApp (/Users/qihanzhang/git/express-angular/node_modules/everyauth/lib/modules/everymodule.js:270:23)
    at Object.everyauth.middleware (/Users/qihanzhang/git/express-angular/node_modules/everyauth/index.js:38:15)
    at Function.app.configure.app.use.express.errorHandler.dumpExceptions (/Users/qihanzhang/git/express-angular/app.js:103:21)
    at Function.app.configure (/Users/qihanzhang/git/express-angular/node_modules/express/lib/application.js:391:61)
    at Object.<anonymous> (/Users/qihanzhang/git/express-angular/app.js:92:5)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
26 Oct 09:55:31 - [nodemon] app crashed - waiting for file changes before starting...

I'm not sure where this consumerKey should be configured, I looked in the everymodule.js but only found this:

/**
 * Convenience method for all you coffee-script lovers, e.g.,
 *
 * everyauth.dropbox.configure
 *   consumerKey:       conf.dropbox.consumerKey
 *   consumerSecret:    conf.dropbox.consumerSecret
 *   findOrCreateUser:  (sess, accessToken, accessSecret, dbMeta) -> users[dbMeta.uid] or= addUser('dropbox', dbMeta)
 *   redirectPath:      '/'
 */
EveryModule.prototype.configure = function (conf) {
  for (var k in conf) {
    this[k](conf[k]);
  }
  return this;
};

any ideas where/how to configure this key? I think I found it in the node_modules/everyauth/lib/modules/oauth.js, but do I need to configure all the other fields as well? Thanks!

var oauth = module.exports =
everyModule.submodule('oauth')
  .configurable({
      apiHost: 'e.g., https://api.twitter.com'
    , oauthHost: 'the host for the OAuth provider'
    , requestTokenPath: "the path on the OAuth provider's domain where we request the request token, e.g., /oauth/request_token"
    , accessTokenPath: "the path on the OAuth provider's domain where we request the access token, e.g., /oauth/access_token"
    , authorizePath: 'the path on the OAuth provider where you direct a visitor to login, e.g., /oauth/authorize'
    , sendCallbackWithAuthorize: 'whether you want oauth_callback=... as a query param send with your request to /oauth/authorize'
    , consumerKey: 'the api key provided by the OAuth provider'
    , consumerSecret: 'the api secret provided by the OAuth provider'
    , myHostname: 'e.g., http://localhost:3000 . Notice no trailing slash'

Solution

  • So I was able to figure it out looking at https://github.com/paullang/express-angular/commit/e224e7296436f1a1a2851b50212b27b66d7adc31

    and replaced:

    everyauth
        .twitter
        .consumerKey(process.env.TWITTER_CONSUMER_KEY)
        .consumerSecret(process.env.TWITTER_CONSUMER_SECRET)
    

    with:

    everyauth
        .twitter
        .consumerKey('JLCGyLzuOK1BjnKPKGyQ')
        .consumerSecret('GNqKfPqtzOcsCtFbGTMqinoATHvBcy1nzCTimeA9M0')
    

    in app.js and now it works!