使用bitly策略在node.js中实现护照认证

时间:2013-07-11 20:11:58

标签: node.js oauth-2.0 passport.js bit.ly

我正在尝试进行身份验证,以便我可以使用链接缩短程序并跟踪用户的指标。我的实现是这样的:

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

路线看起来像这样:

app.get('/auth/bitly',
    passport.authenticate('bitly'));

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

现在我已经完成了我能想到的所有工作,但我总是想出这个愚蠢的错误:

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

任何人都知道这意味着什么,我应该从哪里开始修复它?

3 个答案:

答案 0 :(得分:3)

我刚刚修复了passport-bitly中的错误并提出了拉取请求:https://github.com/dreadjr/passport-bitly/pull/1

@Bitly API:护照是一种在节点世界中获取访问令牌的流行方式,因此最好让这种策略有效。

答案 1 :(得分:2)

我们对这里的护照库并不是很熟悉,但我们最近在几种语言中发布了一些简单的OAuth代码示例,包括node.js:http://bit.ly/bitlyoauthexamples

答案 2 :(得分:0)

如果你正在使用dreadjs的护照比特策略,你会收到这个错误。将 strategy.js 文件替换为simo's fork

截至此日期,Simo的更正尚未合并到dreadjr的护照位存储库中。我可以验证更正是否有效。基本上,原始的驼峰式_profileUrl应该是{em> strategy.js 第49行的_profileURL。正确的行是:

this._profileURL = options.profileURL || 'https://api-ssl.bitly.com/v3/user/info';

在检索所需的JSON信息方面也有所改变。