Search code examples
passport.jsmeanjs

how to properly configure mean.js passport to authenticate with twitter


In my mean.js based app, I'm trying to implement passport twitter authentication.

My twitter section in development.js looks like this:

twitter: {
        clientID: process.env.TWITTER_KEY || ' somekey1234',
        clientSecret: process.env.TWITTER_SECRET || 'someSecret1234',
        callbackURL: '/auth/twitter/callback'
    }

I have signed up with twitter, added my mobile number to my profile, created an app, and got the consumer key and consumer secret.

My Website entry in twitter looks like this:

http://10.211.55.25:3000

My callback url entry looks like this:

http://10.211.55.25:3000/auth/twitter/callback

When I attempt to "Sign up using Twitter" in my app. I get this error:

Error: {"errors":[{"code":32,"message":"Could not authenticate you."}]}
    at Strategy.parseErrorResponse (/home/eugene/dev/node/DataManager_0.2/node_modules/passport-twitter/lib/strategy.js:182:10)
    at Strategy.OAuthStrategy._createOAuthError (/home/eugene/dev/node/DataManager_0.2/node_modules/passport-twitter/node_modules/passport-oauth1/lib/strategy.js:349:16)
    at OAuthStrategy.authenticate (/home/eugene/dev/node/DataManager_0.2/node_modules/passport-twitter/node_modules/passport-oauth1/lib/strategy.js:218:41)
    at exports.OAuth.getOAuthRequestToken (/home/eugene/dev/node/DataManager_0.2/node_modules/passport-twitter/node_modules/passport-oauth1/node_modules/oauth/lib/oauth.js:543:17)
    at exports.OAuth._performSecureRequest.passBackControl (/home/eugene/dev/node/DataManager_0.2/node_modules/passport-twitter/node_modules/passport-oauth1/node_modules/oauth/lib/oauth.js:397:13)
    at IncomingMessage.exports.OAuth._performSecureRequest.request.on.callbackCalled (/home/eugene/dev/node/DataManager_0.2/node_modules/passport-twitter/node_modules/passport-oauth1/node_modules/oauth/lib/oauth.js:409:9)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

As I'm getting this error, the app url in my browser is being set to:

http://10.211.55.25:3000/auth/twitter

What can I do to fix this?


Solution

  • You have an error in the JSON values (An space that is present in TWITTER_KEY value):

    twitter: {
        clientID: process.env.TWITTER_KEY || ' somekey1234',
        clientSecret: process.env.TWITTER_SECRET || 'someSecret1234',
        callbackURL: '/auth/twitter/callback'
    }
    

    should be

    twitter: {
        clientID: process.env.TWITTER_KEY || 'somekey1234',
        clientSecret: process.env.TWITTER_SECRET || 'someSecret1234',
        callbackURL: '/auth/twitter/callback'
    }