Skip to content

Commit a8cc9f6

Browse files
zimegClaude
andcommitted
feat: add oauth.v2.user.access method
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent 1b59fea commit a8cc9f6

7 files changed

Lines changed: 156 additions & 3 deletions

File tree

‎slack_sdk/web/async_client.py‎

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎slack_sdk/web/client.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5379,6 +5379,49 @@ def oauth_v2_exchange(
53795379
kwargs.update({"client_id": client_id, "client_secret": client_secret, "token": token})
53805380
return self.api_call("oauth.v2.exchange", params=kwargs)
53815381

5382+
def oauth_v2_user_access(
5383+
self,
5384+
*,
5385+
client_id: str,
5386+
client_secret: str,
5387+
code: Optional[str] = None,
5388+
code_verifier: Optional[str] = None,
5389+
redirect_uri: Optional[str] = None,
5390+
grant_type: Optional[str] = None,
5391+
refresh_token: Optional[str] = None,
5392+
assertion: Optional[str] = None,
5393+
**kwargs,
5394+
) -> SlackResponse:
5395+
"""Exchanges a temporary OAuth verifier code for a user access token.
5396+
5397+
https://docs.slack.dev/reference/methods/oauth.v2.user.access
5398+
5399+
Args:
5400+
client_id: Issued when you created your application.
5401+
client_secret: Issued when you created your application.
5402+
code: The `code` param returned via the OAuth callback.
5403+
code_verifier: The code_verifier param used to generate the code_challenge originally. Used for PKCE.
5404+
redirect_uri: This must match the originally submitted URI (if one was sent).
5405+
grant_type: The `grant_type` param as described in the OAuth spec.
5406+
refresh_token: The `refresh_token` param as described in the OAuth spec.
5407+
assertion: Identity assertion JWT authorization grant.
5408+
"""
5409+
kwargs.update(
5410+
{
5411+
"code": code,
5412+
"code_verifier": code_verifier,
5413+
"redirect_uri": redirect_uri,
5414+
"grant_type": grant_type,
5415+
"refresh_token": refresh_token,
5416+
"assertion": assertion,
5417+
}
5418+
)
5419+
return self.api_call(
5420+
"oauth.v2.user.access",
5421+
data=kwargs,
5422+
auth={"client_id": client_id, "client_secret": client_secret},
5423+
)
5424+
53825425
def openid_connect_token(
53835426
self,
53845427
client_id: str,

‎slack_sdk/web/legacy_client.py‎

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/slack_sdk/web/mock_web_api_handler.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _handle(self):
7272
# put_nowait is common between Queue & asyncio.Queue, it does not need to be awaited
7373
self.server.queue.put_nowait(self.path)
7474

75-
if self.path in {"/oauth.access", "/oauth.v2.access"}:
75+
if self.path in {"/oauth.access", "/oauth.v2.access", "/oauth.v2.user.access"}:
7676
self.send_response(200)
7777
self.set_common_headers()
7878
if self.headers["authorization"] == "Basic MTExLjIyMjpzZWNyZXQ=":

‎tests/slack_sdk/web/test_web_client.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ def test_issue_690_oauth_v2_access(self):
125125
with self.assertRaises(err.SlackApiError):
126126
self.client.oauth_v2_access(client_id="999.999", client_secret="secret", code="codeeeeeeeeee")
127127

128+
def test_oauth_v2_user_access(self):
129+
self.client.token = ""
130+
resp = self.client.oauth_v2_user_access(client_id="111.222", client_secret="secret", code="codeeeeeeeeee")
131+
self.assertIsNone(resp["error"])
132+
with self.assertRaises(err.SlackApiError):
133+
self.client.oauth_v2_user_access(client_id="999.999", client_secret="secret", code="codeeeeeeeeee")
134+
128135
def test_issue_690_oauth_access(self):
129136
self.client.token = ""
130137
resp = self.client.oauth_access(client_id="111.222", client_secret="secret", code="codeeeeeeeeee")

‎tests/slack_sdk_async/web/test_async_web_client.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ async def test_issue_690_oauth_v2_access_async(self):
101101
code="codeeeeeeeeee",
102102
)
103103

104+
@async_test
105+
async def test_oauth_v2_user_access_async(self):
106+
self.client.token = ""
107+
resp = await self.client.oauth_v2_user_access(
108+
client_id="111.222",
109+
client_secret="secret",
110+
code="codeeeeeeeeee",
111+
)
112+
self.assertIsNone(resp["error"])
113+
with self.assertRaises(err.SlackApiError):
114+
await self.client.oauth_v2_user_access(
115+
client_id="999.999",
116+
client_secret="secret",
117+
code="codeeeeeeeeee",
118+
)
119+
104120
@async_test
105121
async def test_issue_690_oauth_access_async(self):
106122
self.client.token = ""

0 commit comments

Comments
 (0)