File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
integration_tests/samples/oauth Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -123,13 +123,19 @@ def oauth_callback():
123123
124124@app .route ("/slack/events" , methods = ["POST" ])
125125def 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
Original file line number Diff line number Diff line change @@ -135,13 +135,19 @@ async def oauth_callback(req: Request):
135135
136136@app .post ("/slack/events" )
137137async 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" )
You can’t perform that action at this time.
0 commit comments