错误:未经授权的Request.callback。状态:401

时间:2019-10-31 06:34:20

标签: node.js github post webhooks github-api

https://developer.github.com/apps/quickstart-guides/using-the-github-api-in-your-app/

我正在按照GitHub上的上述教程设置GitHub API,但是,我遇到了这个问题。

================================================ ===

我只是运行sudo smee --url https://smee.io/0AcqgdnAAdZA5q --path /event_handler --port 3002  在我的终端中,然后在安装该应用程序的存储库之一中创建一个问题,仅用于测试目的。

然后 smee 尝试将邮件重定向到我的Mac计算机时,出现以下错误

{ Error: Unauthorized
    at Request.callback (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/index.js:706:15)
    at IncomingMessage.parser (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/index.js:916:18)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  status: 401,
  response:
   Response {
     _events: [Object: null prototype] {},
     _eventsCount: 0,
     _maxListeners: undefined,
     res:
      IncomingMessage {
        _readableState: [ReadableState],
        readable: false,
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        socket: [Socket],
        connection: [Socket],
        httpVersionMajor: 1,
        httpVersionMinor: 1,
        httpVersion: '1.1',
        complete: true,
        headers: [Object],
        rawHeaders: [Array],
        trailers: {},
        rawTrailers: [],
        aborted: false,
        upgrade: false,
        url: '',
        method: null,
        statusCode: 401,
        statusMessage: 'Unauthorized ',
        client: [Socket],
        _consuming: false,
        _dumped: false,
        req: [ClientRequest],
        text: '' },
     request:
      Request {
        _events: [Object: null prototype] {},
        _eventsCount: 0,
        _maxListeners: undefined,
        _agent: false,
        _formData: null,
        method: 'POST',
        url: 'http://127.0.0.1:3002/event_handler',
        _header: [Object],
        header: [Object],
        writable: true,
        _redirects: 0,
        _maxRedirects: 5,
        cookies: '',
        qs: {},
        _query: [],
        qsRaw: [],
        _redirectList: [],
        _streamRequest: false,
        _data: [Object],
        req: [ClientRequest],
        protocol: 'http:',
        host: '127.0.0.1:3002',
        _endCalled: true,
        _callback: [Function],
        res: [IncomingMessage],
        response: [Circular],
        called: true },
     req:
      ClientRequest {
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: 7597,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: [Socket],
        connection: [Socket],
        _header:
         'POST /event_handler HTTP/1.1\r\nhost: smee.io\r\nAccept-Encoding: gzip, deflate\r\nuser-agent: GitHub-Hookshot/b4238f9\r\ncontent-type: application/json\r\nconnection: close\r\naccept: */*\r\nx-github-event: issues\r\nx-github-delivery: 2ffd9d80-fba0-11e9-8f34-9987220100a1\r\nx-hub-signature: sha1=9b59ee3122af7a623934083d8d5432f32a7d42d6\r\nx-request-id: f422646b-fb28-4904-9b88-7294c9a01fbe\r\nx-forwarded-for: 140.82.115.249\r\nx-forwarded-proto: https\r\nx-forwarded-port: 443\r\nvia: 1.1 vegur\r\nconnect-time: 0\r\nx-request-start: 1572500103861\r\ntotal-route-time: 0\r\ncontent-length: 7597\r\ntimestamp: 1572500103863\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Agent],
        socketPath: undefined,
        timeout: undefined,
        method: 'POST',
        path: '/event_handler',
        _ended: true,
        res: [IncomingMessage],
        aborted: undefined,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        [Symbol(isCorked)]: false,
        [Symbol(outHeadersKey)]: [Object] },
     text: '',
     body: {},
     files: undefined,
     buffered: true,
     headers:
      { 'content-type': 'text/html;charset=utf-8',
        'content-length': '0',
        'x-xss-protection': '1; mode=block',
        'x-content-type-options': 'nosniff',
        'x-frame-options': 'SAMEORIGIN',
        server: 'WEBrick/1.3.1 (Ruby/2.3.7/2018-03-28)',
        date: 'Thu, 31 Oct 2019 05:35:04 GMT',
        connection: 'close' },
     header:
      { 'content-type': 'text/html;charset=utf-8',
        'content-length': '0',
        'x-xss-protection': '1; mode=block',
        'x-content-type-options': 'nosniff',
        'x-frame-options': 'SAMEORIGIN',
        server: 'WEBrick/1.3.1 (Ruby/2.3.7/2018-03-28)',
        date: 'Thu, 31 Oct 2019 05:35:04 GMT',
        connection: 'close' },
     statusCode: 401,
     status: 401,
     statusType: 4,
     info: false,
     ok: false,
     redirect: false,
     clientError: true,
     serverError: false,
     error:
      { Error: cannot POST /event_handler (401)
          at Response.toError (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/response.js:94:15)
          at ResponseBase._setStatusProperties (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/response-base.js:123:16)
          at new Response (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/response.js:41:8)
          at Request._emitResponse (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/index.js:752:20)
          at IncomingMessage.parser (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/index.js:916:38)
          at IncomingMessage.emit (events.js:203:15)
          at endReadableNT (_stream_readable.js:1145:12)
          at process._tickCallback (internal/process/next_tick.js:63:19) status: 401, text: '', method: 'POST', path: '/event_handler' },
     created: false,
     accepted: false,
     noContent: false,
     badRequest: false,
     unauthorized: true,
     notAcceptable: false,
     forbidden: false,
     notFound: false,
     unprocessableEntity: false,
     type: 'text/html',
     charset: 'utf-8',
     links: {},
     setEncoding: [Function: bound ],
     redirects: [] } }

但是我敢肯定,smee成功地从GitHub服务器接收到了Webhook,将钩子重定向到我的个人Mac计算机上只是错误的。证明是,我可以从 smee 网站查看帖子消息。

I can view the hook on smee website directly

我的Mac计算机上正在运行一个脚本,该脚本用作本地服务器,正在等待 smee 的重定向。但是我认为这与这里的问题无关,因此我不会在此处发布代码。这只是从Github存储库复制的简单的ruby脚本。

1 个答案:

答案 0 :(得分:0)

我通过在.env中为GITHUB_WEBHOOK_SECRET值添加引号解决了我的问题

其中可能包含特殊符号。

检查您的值

https://github.com/github-developer/github-app-template/blob/master/template_server.rb#L135

  • their_digest
  • our_digest
  • WEBHOOK_SECRET