Skip to content

Commit 31599be

Browse files
committed
Add default to CallbackOptions handler args
1 parent afb7a36 commit 31599be

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

examples/oauth_app_settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919

2020
def success(args: SuccessArgs) -> BoltResponse:
21-
return BoltResponse(status=200, body="Thanks!")
21+
# Do anything here ...
22+
# Call the default handler to return HTTP response
23+
return args.default.success(args)
24+
# return BoltResponse(status=200, body="Thanks!")
2225

2326

2427
def failure(args: FailureArgs) -> BoltResponse:

slack_bolt/oauth/async_callback_options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ def __init__( # type: ignore
1717
request: AsyncBoltRequest,
1818
installation: Installation,
1919
settings: "AsyncOAuthSettings",
20+
default: "AsyncCallbackOptions",
2021
):
2122
"""The arguments for a success function.
2223
2324
:param request: The request.
2425
:param installation: The installation data.
2526
:param settings: The settings for OAuth flow.
27+
:param default: The default AsyncCallbackOptions.
2628
"""
2729
self.request = request
2830
self.installation = installation
2931
self.settings = settings
32+
self.default = default
3033

3134

3235
class AsyncFailureArgs:
@@ -38,6 +41,7 @@ def __init__( # type: ignore
3841
error: Optional[Exception] = None,
3942
suggested_status_code: int,
4043
settings: "AsyncOAuthSettings",
44+
default: "AsyncCallbackOptions",
4145
):
4246
"""The arguments for a failure function.
4347
@@ -46,12 +50,14 @@ def __init__( # type: ignore
4650
:param error: An exception if exists.
4751
:param suggested_status_code: The recommended HTTP status code for the failure.
4852
:param settings: The settings for OAuth flow.
53+
:param default: The default AsyncCallbackOptions.
4954
"""
5055
self.request = request
5156
self.reason = reason
5257
self.error = error
5358
self.suggested_status_code = suggested_status_code
5459
self.settings = settings
60+
self.default = default
5561

5662

5763
class AsyncCallbackOptions:

slack_bolt/oauth/async_oauth_flow.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ def __init__(
6969
self.install_path = self.settings.install_path
7070
self.redirect_uri_path = self.settings.redirect_uri_path
7171

72+
self.default_callback_options = DefaultAsyncCallbackOptions(
73+
logger=logger,
74+
state_utils=self.settings.state_utils,
75+
redirect_uri_page_renderer=self.settings.redirect_uri_page_renderer,
76+
)
7277
if settings.callback_options is None:
73-
settings.callback_options = DefaultAsyncCallbackOptions(
74-
logger=logger,
75-
state_utils=self.settings.state_utils,
76-
redirect_uri_page_renderer=self.settings.redirect_uri_page_renderer,
77-
)
78+
settings.callback_options = self.default_callback_options
7879
self.success_handler = settings.callback_options.success
7980
self.failure_handler = settings.callback_options.failure
8081

@@ -186,6 +187,7 @@ async def handle_callback(self, request: AsyncBoltRequest) -> BoltResponse:
186187
reason=error, # type: ignore
187188
suggested_status_code=200,
188189
settings=self.settings,
190+
default=self.default_callback_options,
189191
)
190192
)
191193

@@ -198,6 +200,7 @@ async def handle_callback(self, request: AsyncBoltRequest) -> BoltResponse:
198200
reason="invalid_browser",
199201
suggested_status_code=400,
200202
settings=self.settings,
203+
default=self.default_callback_options,
201204
)
202205
)
203206

@@ -209,6 +212,7 @@ async def handle_callback(self, request: AsyncBoltRequest) -> BoltResponse:
209212
reason="invalid_state",
210213
suggested_status_code=401,
211214
settings=self.settings,
215+
default=self.default_callback_options,
212216
)
213217
)
214218

@@ -221,6 +225,7 @@ async def handle_callback(self, request: AsyncBoltRequest) -> BoltResponse:
221225
reason="missing_code",
222226
suggested_status_code=401,
223227
settings=self.settings,
228+
default=self.default_callback_options,
224229
)
225230
)
226231

@@ -233,6 +238,7 @@ async def handle_callback(self, request: AsyncBoltRequest) -> BoltResponse:
233238
reason="invalid_code",
234239
suggested_status_code=401,
235240
settings=self.settings,
241+
default=self.default_callback_options,
236242
)
237243
)
238244

@@ -247,13 +253,17 @@ async def handle_callback(self, request: AsyncBoltRequest) -> BoltResponse:
247253
error=err,
248254
suggested_status_code=500,
249255
settings=self.settings,
256+
default=self.default_callback_options,
250257
)
251258
)
252259

253260
# display a successful completion page to the end-user
254261
return await self.success_handler(
255262
AsyncSuccessArgs(
256-
request=request, installation=installation, settings=self.settings,
263+
request=request,
264+
installation=installation,
265+
settings=self.settings,
266+
default=self.default_callback_options,
257267
)
258268
)
259269

slack_bolt/oauth/callback_options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ def __init__( # type: ignore
1717
request: BoltRequest,
1818
installation: Installation,
1919
settings: "OAuthSettings",
20+
default: "CallbackOptions",
2021
):
2122
"""The arguments for a success function.
2223
2324
:param request: The request.
2425
:param installation: The installation data.
2526
:param settings: The settings for OAuth flow.
27+
:param default: The default CallbackOptions.
2628
"""
2729
self.request = request
2830
self.installation = installation
2931
self.settings = settings
32+
self.default = default
3033

3134

3235
class FailureArgs:
@@ -38,6 +41,7 @@ def __init__( # type: ignore
3841
error: Optional[Exception] = None,
3942
suggested_status_code: int,
4043
settings: "OAuthSettings",
44+
default: "CallbackOptions",
4145
):
4246
"""The arguments for a failure function.
4347
@@ -46,12 +50,14 @@ def __init__( # type: ignore
4650
:param error: An exception if exists.
4751
:param suggested_status_code: The recommended HTTP status code for the failure.
4852
:param settings: The settings for OAuth flow.
53+
:param default: The default CallbackOptions.
4954
"""
5055
self.request = request
5156
self.reason = reason
5257
self.error = error
5358
self.suggested_status_code = suggested_status_code
5459
self.settings = settings
60+
self.default = default
5561

5662

5763
class CallbackOptions:

slack_bolt/oauth/oauth_flow.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ def __init__(
6969
self.install_path = self.settings.install_path
7070
self.redirect_uri_path = self.settings.redirect_uri_path
7171

72+
self.default_callback_options = DefaultCallbackOptions(
73+
logger=logger,
74+
state_utils=self.settings.state_utils,
75+
redirect_uri_page_renderer=self.settings.redirect_uri_page_renderer,
76+
)
7277
if settings.callback_options is None:
73-
settings.callback_options = DefaultCallbackOptions(
74-
logger=logger,
75-
state_utils=self.settings.state_utils,
76-
redirect_uri_page_renderer=self.settings.redirect_uri_page_renderer,
77-
)
78+
settings.callback_options = self.default_callback_options
7879
self.success_handler = settings.callback_options.success
7980
self.failure_handler = settings.callback_options.failure
8081

@@ -186,6 +187,7 @@ def handle_callback(self, request: BoltRequest) -> BoltResponse:
186187
reason=error,
187188
suggested_status_code=200,
188189
settings=self.settings,
190+
default=self.default_callback_options,
189191
)
190192
)
191193

@@ -198,6 +200,7 @@ def handle_callback(self, request: BoltRequest) -> BoltResponse:
198200
reason="invalid_browser",
199201
suggested_status_code=400,
200202
settings=self.settings,
203+
default=self.default_callback_options,
201204
)
202205
)
203206

@@ -209,6 +212,7 @@ def handle_callback(self, request: BoltRequest) -> BoltResponse:
209212
reason="invalid_state",
210213
suggested_status_code=401,
211214
settings=self.settings,
215+
default=self.default_callback_options,
212216
)
213217
)
214218

@@ -221,6 +225,7 @@ def handle_callback(self, request: BoltRequest) -> BoltResponse:
221225
reason="missing_code",
222226
suggested_status_code=401,
223227
settings=self.settings,
228+
default=self.default_callback_options,
224229
)
225230
)
226231

@@ -233,6 +238,7 @@ def handle_callback(self, request: BoltRequest) -> BoltResponse:
233238
reason="invalid_code",
234239
suggested_status_code=401,
235240
settings=self.settings,
241+
default=self.default_callback_options,
236242
)
237243
)
238244

@@ -247,13 +253,17 @@ def handle_callback(self, request: BoltRequest) -> BoltResponse:
247253
error=err,
248254
suggested_status_code=500,
249255
settings=self.settings,
256+
default=self.default_callback_options,
250257
)
251258
)
252259

253260
# display a successful completion page to the end-user
254261
return self.success_handler(
255262
SuccessArgs(
256-
request=request, installation=installation, settings=self.settings,
263+
request=request,
264+
installation=installation,
265+
settings=self.settings,
266+
default=self.default_callback_options,
257267
)
258268
)
259269

0 commit comments

Comments
 (0)