implementing passport authentication in node.js with bitly strategy


I'm trying to authenticate to bitly so I can use the link-shortener and track the users' metrics. My implementation is like this:

passport.use(new BitlyStrategy({
    clientID: "my client id here",
    clientSecret: "my secret here",
    callbackURL: ""
function (token, tokenSecret, profile, done) {
// Code to put it in the server here.

And the routes look like this:


passport.authenticate('bitly', { failureRedirect: '/', failureFlash: true, failureFlash: 'Invalid bitly Authentication try again.' }),
function(req, res) {
    // Successful authentication, redirect home.

Now I've done everything I can think of to get this working, but I always come up with this stupid error:

Application has thrown an uncaught exception and is terminated:
TypeError: Parameter 'url' must be a string, not undefined
at Object.urlParse [as parse] (url.js:92:11)
at [object Object]._request (C:\DWASFiles\Sites\twitter-mongo\VirtualDirectory0\site\wwwroot\node_modules\passport-bitly\node_modules\passport-oauth\node_modules\oauth\lib\oauth2.js:56:22)
at [object Object].get (C:\DWASFiles\Sites\twitter-mongo\VirtualDirectory0\site\wwwroot\node_modules\passport-bitly\node_modules\passport-oauth\node_modules\oauth\lib\oauth2.js:196:8)
at Strategy.userProfile (C:\DWASFiles\Sites\twitter-mongo\VirtualDirectory0\site\wwwroot\node_modules\passport-bitly\lib\passport-bitly\strategy.js:76:16)
at loadIt (C:\DWASFiles\Sites\twitter-mongo\VirtualDirectory0\site\wwwroot\node_modules\passport-bitly\node_modules\passport-oauth\lib\passport-oauth\strategies\oauth2.js:221:17)
at Strategy._loadUserProfile (C:\DWASFiles\Sites\twitter-mongo\VirtualDirectory0\site\wwwroot\node_modules\passport-bitly\node_modules\passport-oauth\lib\passport-oauth\strategies\oauth2.js:236:25)
at C:\DWASFiles\Sites\twitter-mongo\VirtualDirectory0\site\wwwroot\node_modules\passport-bitly\node_modules\passport-oauth\lib\passport-oauth\strategies\oauth2.js:127:14
at C:\DWASFiles\Sites\twitter-mongo\VirtualDirectory0\site\wwwroot\node_modules\passport-bitly\node_modules\passport-oauth\node_modules\oauth\lib\oauth2.js:178:7
at passBackControl (C:\DWASFiles\Sites\twitter-mongo\VirtualDirectory0\site\wwwroot\node_modules\passport-bitly\node_modules\passport-oauth\node_modules\oauth\lib\oauth2.js:107:9)
at IncomingMessage.<anonymous> (C:\DWASFiles\Sites\twitter-mongo\VirtualDirectory0\site\wwwroot\node_modules\passport-bitly\node_modules\passport-oauth\node_modules\oauth\lib\oauth2.js:124:7

Anyone have any idea what that means, and where I should start to get it fixed?

Problem courtesy of: milestyle


We are not super familiar with the passport library over here but we recently posted some simple OAuth code examples in several languages including node.js here:

Solution courtesy of: Bitly API


I just fixed the bug in passport-bitly and made a pull request:

@Bitly API: passport is a popular way to get access tokens in the node world, so it's good to have this strategy working.

Discussion courtesy of: simo

If you are using dreadjs's passport-bitly strategy, you will get this error. Replace the strategy.js file with that from simo's fork.

As of this date, Simo's corrections have not yet been merged into dreadjr's passport-bitly repository. I can verify that the corrections do work. Basically the original camel-cased _profileUrl should be _profileURL on line 49 of strategy.js. The correct line is:

this._profileURL = options.profileURL || '';

There are changes made in retrieving the JSON information that are needed as well.

Discussion courtesy of: mankind

This recipe can be found in it's original form on Stack Over Flow.