Node Passport-azure-ad error: "unknown authentication strategy "oauth-bearer""
Node Passport-azure-ad error: "unknown authentication strategy "oauth-bearer""
我一定遗漏了一些非常明显的东西。
我一直在尝试 trust/follow 关于这个的官方文档,但我注意到我实际上并没有使用整个 'bearerStrategy' 我在任何地方定义。如果我尝试用 bearerStrategy 替换 oauth-bearer,我会得到完全相同的结果。
设置:
const passport = require('passport');
const BearerStrategy = require('passport-azure-ad').BearerStrategy
index.js 中的端点:
app.use("/andon", passport.authenticate('oauth-bearer', { session: false }), andon);
来自文档文件的配置:
let options = {
identityMetadata: appconfig.get("creds.identityMetadata"),
clientID: appconfig.get("creds.clientID"),
passReqToCallback: appconfig.get("creds.passReqToCallback")
}
let bearerStrategy = new BearerStrategy(options,
function(token, done) {
log.info('verifying the user');
log.info(token, 'was the token retreived');
findById(token.oid, function(err, user) {
if (err) {
return done(err);
}
if (!user) {
// "Auto-registration"
log.info('User was added automatically as they were new. Their oid is: ', token.oid);
users.push(token);
owner = token.oid;
return done(null, token);
}
owner = token.oid;
return done(null, user, token);
});
}
);
您可能缺少以下配置步骤:
var passport = require('passport')
app.use(passport.initialize());
var BearerStrategy = require('passport-azure-ad').BearerStrategy
var bearerStrategy = new BearerStrategy (...)
passport.use(bearerStrategy);
缺少这两个:
app.use(passport.initialize());
passport.use(bearerStrategy)
将它们添加到正确的位置,现在一切正常。
我一定遗漏了一些非常明显的东西。
我一直在尝试 trust/follow 关于这个的官方文档,但我注意到我实际上并没有使用整个 'bearerStrategy' 我在任何地方定义。如果我尝试用 bearerStrategy 替换 oauth-bearer,我会得到完全相同的结果。
设置:
const passport = require('passport');
const BearerStrategy = require('passport-azure-ad').BearerStrategy
index.js 中的端点:
app.use("/andon", passport.authenticate('oauth-bearer', { session: false }), andon);
来自文档文件的配置:
let options = {
identityMetadata: appconfig.get("creds.identityMetadata"),
clientID: appconfig.get("creds.clientID"),
passReqToCallback: appconfig.get("creds.passReqToCallback")
}
let bearerStrategy = new BearerStrategy(options,
function(token, done) {
log.info('verifying the user');
log.info(token, 'was the token retreived');
findById(token.oid, function(err, user) {
if (err) {
return done(err);
}
if (!user) {
// "Auto-registration"
log.info('User was added automatically as they were new. Their oid is: ', token.oid);
users.push(token);
owner = token.oid;
return done(null, token);
}
owner = token.oid;
return done(null, user, token);
});
}
);
您可能缺少以下配置步骤:
var passport = require('passport')
app.use(passport.initialize());
var BearerStrategy = require('passport-azure-ad').BearerStrategy
var bearerStrategy = new BearerStrategy (...)
passport.use(bearerStrategy);
缺少这两个:
app.use(passport.initialize());
passport.use(bearerStrategy)
将它们添加到正确的位置,现在一切正常。