Skip to content

Commit 677f3b7

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

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
@@ -5541,6 +5541,49 @@ def oauth_v2_exchange(
55415541
kwargs.update({"client_id": client_id, "client_secret": client_secret, "token": token})
55425542
return self.api_call("oauth.v2.exchange", params=kwargs)
55435543

5544+
def oauth_v2_user_access(
5545+
self,
5546+
*,
5547+
client_id: str,
5548+
client_secret: str,
5549+
code: Optional[str] = None,
5550+
code_verifier: Optional[str] = None,
5551+
redirect_uri: Optional[str] = None,
5552+
grant_type: Optional[str] = None,
5553+
refresh_token: Optional[str] = None,
5554+
assertion: Optional[str] = None,
5555+
**kwargs,
5556+
) -> SlackResponse:
5557+
"""Exchanges a temporary OAuth verifier code for a user access token.
5558+
5559+
https://docs.slack.dev/reference/methods/oauth.v2.user.access
5560+
5561+
Args:
5562+
client_id: Issued when you created your application.
5563+
client_secret: Issued when you created your application.
5564+
code: The `code` param returned via the OAuth callback.
5565+
code_verifier: The code_verifier param used to generate the code_challenge originally. Used for PKCE.
5566+
redirect_uri: This must match the originally submitted URI (if one was sent).
5567+
grant_type: The `grant_type` param as described in the OAuth spec.
5568+
refresh_token: The `refresh_token` param as described in the OAuth spec.
5569+
assertion: Identity assertion JWT authorization grant.
5570+
"""
5571+
kwargs.update(
5572+
{
5573+
"code": code,
5574+
"code_verifier": code_verifier,
5575+
"redirect_uri": redirect_uri,
5576+
"grant_type": grant_type,
5577+
"refresh_token": refresh_token,
5578+
"assertion": assertion,
5579+
}
5580+
)
5581+
return self.api_call(
5582+
"oauth.v2.user.access",
5583+
data=kwargs,
5584+
auth={"client_id": client_id, "client_secret": client_secret},
5585+
)
5586+
55445587
def openid_connect_token(
55455588
self,
55465589
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)