Skip to content

Commit db6a358

Browse files
fix integration samples
1 parent bfe8ff8 commit db6a358

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

integration_tests/samples/oauth/oauth_v2.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,19 @@ def oauth_callback():
123123

124124
@app.route("/slack/events", methods=["POST"])
125125
def slack_app():
126+
data = request.get_data()
126127
if not signature_verifier.is_valid(
127-
body=request.get_data(),
128+
body=data,
128129
timestamp=request.headers.get("X-Slack-Request-Timestamp"),
129130
signature=request.headers.get("X-Slack-Signature"),
130131
):
131132
return make_response("invalid request", 403)
132133

134+
if data and b"url_verification" in data:
135+
body = json.loads(data)
136+
if body.get("type") == "url_verification" and "challenge" in body:
137+
return make_response(body["challenge"], 200)
138+
133139
if "command" in request.form and request.form["command"] == "/open-modal":
134140
try:
135141
enterprise_id = request.form.get("enterprise_id")
@@ -193,4 +199,4 @@ def slack_app():
193199

194200
# python3 integration_tests/samples/oauth/oauth_v2.py
195201
# ngrok http 3000
196-
# https://{yours}.ngrok.io/slack/oauth/start
202+
# https://{yours}.ngrok.io/slack/install

integration_tests/samples/oauth/oauth_v2_async.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,19 @@ async def oauth_callback(req: Request):
135135

136136
@app.post("/slack/events")
137137
async def slack_app(req: Request):
138+
data=req.body.decode("utf-8")
138139
if not signature_verifier.is_valid(
139-
body=req.body.decode("utf-8"),
140+
body=data,
140141
timestamp=req.headers.get("X-Slack-Request-Timestamp"),
141142
signature=req.headers.get("X-Slack-Signature"),
142143
):
143144
return HTTPResponse(status=403, body="invalid request")
144145

146+
if data and "url_verification" in data:
147+
body = json.loads(data)
148+
if body.get("type") == "url_verification" and "challenge" in body:
149+
return HTTPResponse(status=200, body=body["challenge"])
150+
145151
if "command" in req.form and req.form.get("command") == "/open-modal":
146152
try:
147153
enterprise_id = req.form.get("enterprise_id")

0 commit comments

Comments
 (0)