Skip to content

Commit edd9279

Browse files
committed
Fix #158 by adding token_verification_enabled option to App
1 parent 8efa2ba commit edd9279

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

slack_bolt/app/app.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(
7676
signing_secret: Optional[str] = None,
7777
# for single-workspace apps
7878
token: Optional[str] = None,
79+
token_verification_enabled: bool = True,
7980
client: Optional[WebClient] = None,
8081
# for multi-workspace apps
8182
authorize: Optional[Callable[..., AuthorizeResult]] = None,
@@ -95,6 +96,7 @@ def __init__(
9596
:param process_before_response: True if this app runs on Function as a Service. (Default: False)
9697
:param signing_secret: The Signing Secret value used for verifying requests from Slack.
9798
:param token: The bot access token required only for single-workspace app.
99+
:param token_verification_enabled: Verifies the validity of the given token if True.
98100
:param client: The singleton slack_sdk.WebClient instance for this app.
99101
:param authorize: The function to authorize an incoming request from Slack
100102
by checking if there is a team/user in the installation data.
@@ -227,9 +229,11 @@ def __init__(
227229
)
228230

229231
self._init_middleware_list_done = False
230-
self._init_middleware_list()
232+
self._init_middleware_list(
233+
token_verification_enabled=token_verification_enabled
234+
)
231235

232-
def _init_middleware_list(self):
236+
def _init_middleware_list(self, token_verification_enabled: bool):
233237
if self._init_middleware_list_done:
234238
return
235239
self._middleware_list.append(
@@ -240,7 +244,9 @@ def _init_middleware_list(self):
240244
if self._oauth_flow is None:
241245
if self._token is not None:
242246
try:
243-
auth_test_result = self._client.auth_test(token=self._token)
247+
auth_test_result = None
248+
if token_verification_enabled:
249+
auth_test_result = self._client.auth_test(token=self._token)
244250
self._middleware_list.append(
245251
SingleTeamAuthorization(auth_test_result=auth_test_result)
246252
)

tests/scenario_tests/test_app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ def test_token_absence(self):
6767
with pytest.raises(BoltError):
6868
App(signing_secret="valid", token="")
6969

70+
def test_token_verification_enabled_False(self):
71+
App(
72+
signing_secret="valid",
73+
client=self.web_client,
74+
token_verification_enabled=False,
75+
)
76+
App(
77+
signing_secret="valid",
78+
token="xoxb-invalid",
79+
token_verification_enabled=False,
80+
)
81+
82+
assert self.mock_received_requests.get("/auth.test") is None
83+
7084
# --------------------------
7185
# multi teams auth
7286
# --------------------------

0 commit comments

Comments
 (0)