停留在V2 OAuth认证流程的第三步



我已经创建了我的第一个bot,现在我想提交到Slack应用程序目录。正如教程所说,当用户批准我的应用程序时,我应该为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"
]
}
}

我做错了什么?

Andrea

当我查看该方法的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.

你传递的头或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参数列表中提供了一个代码-尽管是无效的代码。

最新更新