如何在fastify中使用node-sspi

问题描述

我要使用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,function (err) {
      res.finished || next()
    })
  },handler: function (req,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
})

“固定”:“ ^ 3.3.0”, “ node-sspi”:“ ^ 0.2.8”,

解决方法

问题在于,像中间件这样的表达在fastify实例上不起作用。该解决方案涉及fastify-express

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,(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,userGroups })
  })
})

fastify.listen(3000,(err) => {
  if (err) throw err
})

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...