我使用ngrok +烧瓶+ python来响应OAuth的invalid_code
流,并且我收到了一个invalid_code
错误。
下面是用松弛客户端文档描述的步骤,到目前为止,我的代码非常简单:
import os
import slack
from flask import Flask, request
app = Flask(__name__)
SLACK_CLIENT_ID = os.environ['SLACK_CLIENT_ID']
SLACK_CLIENT_SECRET = os.environ['SLACK_CLIENT_SECRET']
@app.route('/install', methods=['GET', 'POST'])
def install():
# Retrieve the auth code from the request params
auth_code = request.args['code']
# An empty string is a valid token for this request
client = slack.WebClient(token='')
# Request the auth tokens from Slack
response = client.oauth_access(
client_id=SLACK_CLIENT_ID,
client_secret=SLACK_CLIENT_SECRET,
code=auth_code
)
print(response)
if __name__ == '__main__':
app.run()
我启动应用程序安装从“添加”按钮,在我的Slack工作区的管理应用程序页面。我可以确认,一旦安装启动,我就收到了预期的code
,并且它被正确地传递到slack.BaseClient.api_call()
函数,该函数最终将请求发送到https://slack.com/api/oauth.access
。
我希望来自oauth_access
调用的响应是一个包含我的访问令牌的JSON对象,但是,我得到:
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'invalid_code', 'warning': 'superfluous_charset', 'response_metadata': {'warnings': ['superfluous_charset']}}
我试着用所需的参数将带有curl的帖子发送到Slack的端点,并且按预期的方式工作。我也尝试过使用requests.post()
,这也如预期的那样有效。因此,我怀疑我使用的松弛客户端不正确或误解了什么。有人能帮我指出正确的方向吗?
发布于 2019-10-07 19:17:24
这似乎是Python的一个问题。我认为这个请求解决了这个问题
https://github.com/slackapi/python-slackclient/pull/527
同时,可能更容易恢复到2.1.0版本。
发布于 2019-10-11 20:57:51
https://stackoverflow.com/questions/58231065
复制相似问题