我正在尝试对bitly进行身份验证,以便使用链接缩短器并跟踪用户的度量。我的实现是这样的:
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:DWASFilesSitestwitter-mongoVirtualDirectory0sitewwwrootnode_modulespassport-bitlynode_modulespassport-oauthnode_modulesoauthliboauth2.js:56:22)
at [object Object].get (C:DWASFilesSitestwitter-mongoVirtualDirectory0sitewwwrootnode_modulespassport-bitlynode_modulespassport-oauthnode_modulesoauthliboauth2.js:196:8)
at Strategy.userProfile (C:DWASFilesSitestwitter-mongoVirtualDirectory0sitewwwrootnode_modulespassport-bitlylibpassport-bitlystrategy.js:76:16)
at loadIt (C:DWASFilesSitestwitter-mongoVirtualDirectory0sitewwwrootnode_modulespassport-bitlynode_modulespassport-oauthlibpassport-oauthstrategiesoauth2.js:221:17)
at Strategy._loadUserProfile (C:DWASFilesSitestwitter-mongoVirtualDirectory0sitewwwrootnode_modulespassport-bitlynode_modulespassport-oauthlibpassport-oauthstrategiesoauth2.js:236:25)
at C:DWASFilesSitestwitter-mongoVirtualDirectory0sitewwwrootnode_modulespassport-bitlynode_modulespassport-oauthlibpassport-oauthstrategiesoauth2.js:127:14
at C:DWASFilesSitestwitter-mongoVirtualDirectory0sitewwwrootnode_modulespassport-bitlynode_modulespassport-oauthnode_modulesoauthliboauth2.js:178:7
at passBackControl (C:DWASFilesSitestwitter-mongoVirtualDirectory0sitewwwrootnode_modulespassport-bitlynode_modulespassport-oauthnode_modulesoauthliboauth2.js:107:9)
at IncomingMessage.<anonymous> (C:DWASFilesSitestwitter-mongoVirtualDirectory0sitewwwrootnode_modulespassport-bitlynode_modulespassport-oauthnode_modulesoauthliboauth2.js:124:7
有人知道这意味着什么吗?我应该从哪里开始修复它?
我刚刚修复了passport-bitly
中的错误,并发出了一个pull请求:https://github.com/dreadjr/passport-bitly/pull/1
@Bitly API:passport是一种在节点世界中获得访问令牌的流行方式,所以让这种策略发挥作用是很好的。
我们对这里的passport库不是很熟悉,但我们最近发布了一些简单的OAuth代码示例,这些示例使用了几种语言,包括node.js:http://bit.ly/bitlyoauthexamples
如果您使用的是daryjs的passport bitly策略,则会出现此错误。将策略.js文件替换为simo的fork.中的文件
截至目前,Simo的更正尚未合并到dreadjr的护照bitly存储库中。我可以验证更正是否有效。基本上,原始的驼色外壳的_profileUrl
应该是strategy.js第49行的_profileURL
。正确的行是:
this._profileURL = options.profileURL || 'https://api-ssl.bitly.com/v3/user/info';
在检索JSON信息时也需要进行一些更改。