【问题标题】:How to add authentication to coffescript HTTP-Listener (hubot)如何向 coffescript HTTP-Listener (hubot) 添加身份验证
【发布时间】:2019-10-27 17:16:21
【问题描述】:

我想为 Hubot 的咖啡脚本添加一个简单的用户密码验证。这应该充当向rocketchat 发送消息的“桥梁”。我设法在没有身份验证的情况下发出 HTTP-Post 请求。

到目前为止我得到的脚本运行良好,但没有身份验证:

module.exports = (robot) ->
  robot.router.post '/hubot/say', (req, res) ->

    recipient = req.body.recipient
    message = req.body.message
    dm = req.body.directmessage
    response = "OK"
    robot.logger.info "DM: #{dm}; Recipient: #{recipient}; Message: #{message}"

    if dm == '0'
      #robot.logger.info "Message '#{message}' received for room #{recipient}"

      room = recipient
      user = robot.brain.userForId 'broadcast'
      user.room = room
      user.type = 'groupchat'

      if message
        robot.adapter.send({room, user: {} }, message)

    if dm == '1'
      user = recipient

      if message
        robot.adapter.sendDirect({ user: { name: "#{user}"} }, message)

    res.writeHead 200, {'Content-Type': 'text/plain'}
    res.end response

【问题讨论】:

    标签: coffeescript hubot


    【解决方案1】:

    Hubot 有一个内置的 express web 框架,robot.router 实际上是一个express router。因此,您可以使用basic-auth 库或参考Basic HTTP authentication with Node and Express 4 等问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-04
      • 2017-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多