forked from slackapi/bolt-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthorize_result.py
More file actions
74 lines (68 loc) · 2.4 KB
/
authorize_result.py
File metadata and controls
74 lines (68 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from typing import Optional
from slack_sdk.web import SlackResponse
class AuthorizeResult(dict):
enterprise_id: Optional[str]
team_id: Optional[str]
bot_id: Optional[str]
bot_user_id: Optional[str]
bot_token: Optional[str]
user_id: Optional[str]
user_token: Optional[str]
def __init__(
self,
*,
enterprise_id: Optional[str],
team_id: Optional[str],
# bot
bot_user_id: Optional[str] = None,
bot_id: Optional[str] = None,
bot_token: Optional[str] = None,
# user
user_id: Optional[str] = None,
user_token: Optional[str] = None,
):
"""The `auth.test` API result for an incoming request.
:param enterprise_id: Organization ID (Enterprise Grid)
:param team_id: Workspace ID
:param bot_user_id: Bot user's User ID
:param bot_id: Bot ID
:param bot_token: Bot user access token starting with xoxb-
:param user_id: The request user ID
:param user_token: User access token starting with xoxp-
"""
self["enterprise_id"] = self.enterprise_id = enterprise_id
self["team_id"] = self.team_id = team_id
# bot
self["bot_user_id"] = self.bot_user_id = bot_user_id
self["bot_id"] = self.bot_id = bot_id
self["bot_token"] = self.bot_token = bot_token
# user
self["user_id"] = self.user_id = user_id
self["user_token"] = self.user_token = user_token
@classmethod
def from_auth_test_response(
cls,
*,
bot_token: Optional[str] = None,
user_token: Optional[str] = None,
auth_test_response: SlackResponse,
) -> "AuthorizeResult":
bot_user_id: Optional[str] = ( # type:ignore
auth_test_response.get("user_id")
if auth_test_response.get("bot_id") is not None
else None
)
user_id: Optional[str] = ( # type:ignore
auth_test_response.get("user_id")
if auth_test_response.get("bot_id") is None
else None
)
return AuthorizeResult(
enterprise_id=auth_test_response.get("enterprise_id"),
team_id=auth_test_response.get("team_id"),
bot_id=auth_test_response.get("bot_id"),
bot_user_id=bot_user_id,
user_id=user_id,
bot_token=bot_token,
user_token=user_token,
)