Skip to content

Commit 6bf2399

Browse files
authored
Add team parameter support to the authorize URL generators (#1345)
1 parent 07c0e06 commit 6bf2399

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

integration_tests/web/test_issue_594.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def test_no_preview_image(self):
7676
external_id=external_id,
7777
external_url=external_url,
7878
title="Slack (Wikipedia)",
79-
indexable_file_contents="Slack is a proprietary business communication platform developed by Slack Technologies.".encode("utf-8"),
79+
indexable_file_contents="Slack is a proprietary business communication platform developed by Slack Technologies.".encode(
80+
"utf-8"
81+
),
8082
)
8183
self.assertIsNotNone(creation)
8284

slack_sdk/oauth/authorize_url_generator/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(
1717
self.user_scopes = user_scopes
1818
self.authorization_url = authorization_url
1919

20-
def generate(self, state: str) -> str:
20+
def generate(self, state: str, team: Optional[str] = None) -> str:
2121
scopes = ",".join(self.scopes) if self.scopes else ""
2222
user_scopes = ",".join(self.user_scopes) if self.user_scopes else ""
2323
url = (
@@ -29,6 +29,8 @@ def generate(self, state: str) -> str:
2929
)
3030
if self.redirect_uri is not None:
3131
url += f"&redirect_uri={self.redirect_uri}"
32+
if team is not None:
33+
url += f"&team={team}"
3234
return url
3335

3436

@@ -48,7 +50,7 @@ def __init__(
4850
self.scopes = scopes
4951
self.authorization_url = authorization_url
5052

51-
def generate(self, state: str, nonce: Optional[str] = None) -> str:
53+
def generate(self, state: str, nonce: Optional[str] = None, team: Optional[str] = None) -> str:
5254
scopes = ",".join(self.scopes) if self.scopes else ""
5355
url = (
5456
f"{self.authorization_url}?"
@@ -58,6 +60,8 @@ def generate(self, state: str, nonce: Optional[str] = None) -> str:
5860
f"scope={scopes}&"
5961
f"redirect_uri={self.redirect_uri}"
6062
)
63+
if team is not None:
64+
url += f"&team={team}"
6165
if nonce is not None:
6266
url += f"&nonce={nonce}"
6367
return url

tests/slack_sdk/oauth/authorize_url_generator/test_generator.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from slack_sdk.oauth import AuthorizeUrlGenerator
3+
from slack_sdk.oauth import AuthorizeUrlGenerator, OpenIDConnectAuthorizeUrlGenerator
44

55

66
class TestGenerator(unittest.TestCase):
@@ -28,5 +28,45 @@ def test_base_url(self):
2828
authorization_url="https://www.example.com/authorize",
2929
)
3030
url = generator.generate("state-value")
31-
expected = "https://www.example.com/authorize?state=state-value&client_id=111.222&scope=chat:write,commands&user_scope=search:read"
31+
expected = (
32+
"https://www.example.com/authorize"
33+
"?state=state-value"
34+
"&client_id=111.222"
35+
"&scope=chat:write,commands"
36+
"&user_scope=search:read"
37+
)
38+
self.assertEqual(expected, url)
39+
40+
def test_team(self):
41+
generator = AuthorizeUrlGenerator(
42+
client_id="111.222",
43+
scopes=["chat:write", "commands"],
44+
user_scopes=["search:read"],
45+
)
46+
url = generator.generate(state="state-value", team="T12345")
47+
expected = (
48+
"https://slack.com/oauth/v2/authorize"
49+
"?state=state-value"
50+
"&client_id=111.222"
51+
"&scope=chat:write,commands&user_scope=search:read"
52+
"&team=T12345"
53+
)
54+
self.assertEqual(expected, url)
55+
56+
def test_openid_connect(self):
57+
generator = OpenIDConnectAuthorizeUrlGenerator(
58+
client_id="111.222",
59+
redirect_uri="https://www.example.com/oidc/callback",
60+
scopes=["openid"],
61+
)
62+
url = generator.generate(state="state-value", nonce="nnn", team="T12345")
63+
expected = (
64+
"https://slack.com/openid/connect/authorize"
65+
"?response_type=code&state=state-value"
66+
"&client_id=111.222"
67+
"&scope=openid"
68+
"&redirect_uri=https://www.example.com/oidc/callback"
69+
"&team=T12345"
70+
"&nonce=nnn"
71+
)
3272
self.assertEqual(expected, url)

0 commit comments

Comments
 (0)