Skip to content

Commit 99e77eb

Browse files
authored
Add team param support to the /slack/install endpoint (#853)
1 parent c6f3e9a commit 99e77eb

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

slack_bolt/oauth/async_oauth_flow.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ async def issue_new_state(self, request: AsyncBoltRequest) -> str:
194194
return await self.settings.state_store.async_issue()
195195

196196
async def build_authorize_url(self, state: str, request: AsyncBoltRequest) -> str:
197-
return self.settings.authorize_url_generator.generate(state)
197+
team_ids: Optional[Sequence[str]] = request.query.get("team")
198+
return self.settings.authorize_url_generator.generate(
199+
state=state,
200+
team=team_ids[0] if team_ids is not None else None,
201+
)
198202

199203
async def build_install_page_html(self, url: str, request: AsyncBoltRequest) -> str:
200204
return _build_default_install_page_html(url)

slack_bolt/oauth/oauth_flow.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ def issue_new_state(self, request: BoltRequest) -> str:
192192
return self.settings.state_store.issue()
193193

194194
def build_authorize_url(self, state: str, request: BoltRequest) -> str:
195-
return self.settings.authorize_url_generator.generate(state)
195+
team_ids: Optional[Sequence[str]] = request.query.get("team")
196+
return self.settings.authorize_url_generator.generate(
197+
state=state,
198+
team=team_ids[0] if team_ids is not None else None,
199+
)
196200

197201
def build_install_page_html(self, url: str, request: BoltRequest) -> str:
198202
return _build_default_install_page_html(url)

tests/slack_bolt/oauth/test_oauth_flow.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ def test_handle_installation_no_rendering(self):
8383
assert "https://slack.com/oauth/v2/authorize?state=" in location_header
8484
assert resp.headers.get("set-cookie") is not None
8585

86+
def test_handle_installation_team_param(self):
87+
oauth_flow = OAuthFlow(
88+
settings=OAuthSettings(
89+
client_id="111.222",
90+
client_secret="xxx",
91+
scopes=["chat:write", "commands"],
92+
user_scopes=["search:read"],
93+
installation_store=FileInstallationStore(),
94+
install_page_rendering_enabled=False, # disabled
95+
state_store=FileOAuthStateStore(expiration_seconds=120),
96+
)
97+
)
98+
req = BoltRequest(body="", query={"team": "T12345"})
99+
resp = oauth_flow.handle_installation(req)
100+
assert resp.status == 302
101+
location_header = resp.headers.get("location")[0]
102+
assert "https://slack.com/oauth/v2/authorize?state=" in location_header
103+
assert "&team=T12345" in location_header
104+
assert resp.headers.get("set-cookie") is not None
105+
86106
def test_handle_installation_no_state_validation(self):
87107
oauth_flow = OAuthFlow(
88108
settings=OAuthSettings(

tests/slack_bolt_async/oauth/test_async_oauth_flow.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@ async def test_handle_installation_no_rendering(self):
130130
assert "https://slack.com/oauth/v2/authorize?state=" in location_header
131131
assert resp.headers.get("set-cookie") is not None
132132

133+
@pytest.mark.asyncio
134+
async def test_handle_installation_team_param(self):
135+
oauth_flow = AsyncOAuthFlow(
136+
settings=AsyncOAuthSettings(
137+
client_id="111.222",
138+
client_secret="xxx",
139+
scopes=["chat:write", "commands"],
140+
installation_store=FileInstallationStore(),
141+
install_page_rendering_enabled=False, # disabled
142+
state_store=FileOAuthStateStore(expiration_seconds=120),
143+
)
144+
)
145+
req = AsyncBoltRequest(body="", query={"team": "T12345"})
146+
resp = await oauth_flow.handle_installation(req)
147+
assert resp.status == 302
148+
location_header = resp.headers.get("location")[0]
149+
assert "https://slack.com/oauth/v2/authorize?state=" in location_header
150+
assert "&team=T12345" in location_header
151+
assert resp.headers.get("set-cookie") is not None
152+
133153
@pytest.mark.asyncio
134154
async def test_handle_installation_no_state_validation(self):
135155
oauth_flow = AsyncOAuthFlow(

0 commit comments

Comments
 (0)