卡在 V2 OAuth 身份验证流程的第三步

Stuck on the third step of the V2 OAuth authentication flow

我已经创建了我的第一个机器人,现在我想提交到 Slack App 目录。 正如 tutorial 所说,我应该创建一个端点,当用户批准我的应用程序时,Slack 可以到达该端点。 Slack 应该给我发送一个临时代码,然后我应该将其发回给他们的 OAuth API。这是相关代码(顺便说一句,它是一个 NestJS 应用程序):

@Get()
auth(@Query('code') code: string) {
  const url = 'https://slack.com/api/oauth.v2.access';
  const message = {
    client_id: 'my.client.id',
    client_secret: 'my.client.secret',
    code: 'my.code'
  }
  return this.httpService.post(url, message);
}

但是,我收到以下错误:

{
  "ok": false,
  "error": "invalid_arguments",
  "response_metadata": {
    "messages": [
      "[ERROR] missing required field: code"
    ]
  }
}

我做错了什么?

安德里亚,

当我查看该方法的 slack api 定义时:

https://api.slack.com/methods/oauth.v2.access

我注意到上面写着

Present arguments as parameters in application/x-www-form-urlencoded querystring or POST body. This method does not currently accept application/json.

您传递的是 header 还是 url 编码参数?

'Content-Type': 'application/x-www-form-urlencoded',

我问的原因是如果我在浏览器中访问这样的东西

https://slack.com/api/oauth.v2.access?client_id=00000&client_secret=11111&code=33333

我真的得到了

{"ok":false,"error":"invalid_code"}

这是正确的,因为我在 url 参数列表中提供了代码 - 尽管代码无效。