我正在尝试使用 OAuth2orize 并为 API 端点使用 BearerStrategy,如Git中的示例中所述。代码如下
passport.use(new BearerStrategy(
function(accessToken, done){
accessTokens.find(accesstoken, function(err, token){
if (err) {return done(err);}
if (!token) {return done(null, false); }
users.find(token.user_id, function(err, user){
if (err) { return done(err); }
if (!user) { return done(null, false); }
var info = { scope: '*' }
done(null, user, info);
});
});
}
));
当我尝试开始时,我收到以下错误:
/Users/saransh2012/Developer/vypics/node_modules/passport/lib/passport/index.js:51
if (!name) throw new Error('authentication strategies must have a name');
^
Error: authentication strategies must have a name
at Passport.use (/Users/saransh2012/Developer/vypics/node_modules/passport/lib/passport/index.js:51:20)
at Object.<anonymous> (/Users/saransh2012/Developer/vypics/android_app/auth.js:54:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/saransh2012/Developer/vypics/android_app/app.js:11:1)
at Module._compile (module.js:456:26)
在同一个文件中,我也在做 New BasicStrategy 并且它正在工作,但这仍然不起作用。