我想使用https://github.com/abbr/nodesspi
我想用的是证明,而不是表达。它看起来应该只是起作用,但它不起作用。它几乎相当于快件片段。我在身份验证函数中得到一个错误,告诉我传递了一个错误的参数。
const fastify = require('fastify')({
logger: true,
})
fastify.route({
method: 'GET',
url: '/login',
onRequest: function (req, res, next) {
var nodeSSPI = require('node-sspi')
var nodeSSPIObj = new nodeSSPI({
retrieveGroups: true
})
nodeSSPIObj.authenticate(req, res, function (err) {
res.finished || next()
})
},
handler: function (req, res, next) {
var out =
'Hello ' +
req.connection.user +
'! Your sid is ' +
req.connection.userSid +
' and you belong to following groups:<br/><ul>'
if (req.connection.userGroups) {
for (var i in req.connection.userGroups) {
out += '<li>' + req.connection.userGroups[i] + '</li><br/>\n'
}
}
out += '</ul>'
res.send(out)
}
})
fastify.listen(4000, err => {
if (err) throw err
})"fastify":"^3.3.0",“节点-sspi”:"^0.2.8",
发布于 2020-08-29 23:31:36
问题是,像中间件一样的表达式不适用于fastify实例。解决方案涉及到法蒂菲-特快
const fastify = require('fastify')({ logger: true })
fastify.register(async (fastify) => {
await fastify.register(require('fastify-express'))
const nodeSSPI = require('node-sspi')
const nodeSSPIObj = new nodeSSPI()
fastify.use((req, reply, done) => {
nodeSSPIObj.authenticate(req, reply, (err) => {
if (err) return reply.code(500).send({ error: err })
reply.finished || done()
})
})
fastify.get('/', (req, reply) => {
const { userSid, user, userGroups } = req.connection
return reply.send({ userSid, user, userGroups })
})
})
fastify.listen(3000, (err) => {
if (err) throw err
})https://stackoverflow.com/questions/63618975
复制相似问题