0
# Authentication & Authorization
1
2
Authentication and authorization functionality for Slack API access, including token validation, revocation, and OAuth flow implementation.
3
4
## Capabilities
5
6
### Authentication Testing
7
8
Test your authentication token and retrieve information about the authenticated user or bot.
9
10
```python { .api }
11
def test(self):
12
"""
13
Test authentication token and return information about the authenticated user/bot.
14
15
Returns:
16
Response: Contains user/bot information including user_id, team_id, and token scope
17
"""
18
```
19
20
Usage:
21
```python
22
slack = Slacker(token)
23
response = slack.auth.test()
24
if response.successful:
25
user_id = response.body['user_id']
26
team_id = response.body['team_id']
27
```
28
29
### Token Revocation
30
31
Revoke the current authentication token to invalidate access.
32
33
```python { .api }
34
def revoke(self, test=True):
35
"""
36
Revoke the current authentication token.
37
38
Args:
39
test (bool): Whether to test token validity before revoking (default: True)
40
41
Returns:
42
Response: Confirmation of token revocation
43
"""
44
```
45
46
### OAuth Access Token
47
48
Exchange an OAuth code for an access token during the OAuth flow.
49
50
```python { .api }
51
def access(self, client_id, client_secret, code, redirect_uri=None):
52
"""
53
Exchange OAuth code for access token.
54
55
Args:
56
client_id (str): Slack app client ID
57
client_secret (str): Slack app client secret
58
code (str): OAuth authorization code
59
redirect_uri (str, optional): Redirect URI used in authorization
60
61
Returns:
62
Response: Contains access_token and other OAuth response data
63
"""
64
```
65
66
### OAuth Token Exchange
67
68
Exchange an OAuth code for a workspace token with additional options.
69
70
```python { .api }
71
def token(self, client_id, client_secret, code, redirect_uri=None, single_channel=None):
72
"""
73
Exchange OAuth code for workspace token with extended options.
74
75
Args:
76
client_id (str): Slack app client ID
77
client_secret (str): Slack app client secret
78
code (str): OAuth authorization code
79
redirect_uri (str, optional): Redirect URI used in authorization
80
single_channel (str, optional): Restrict token to single channel
81
82
Returns:
83
Response: Contains access_token and workspace information
84
"""
85
```
86
87
## Types
88
89
```python { .api }
90
class Auth(BaseAPI):
91
"""Authentication and authorization endpoint handler."""
92
def test(self): ...
93
def revoke(self, test=True): ...
94
95
class OAuth(BaseAPI):
96
"""OAuth flow endpoint handler."""
97
def access(self, client_id, client_secret, code, redirect_uri=None): ...
98
def token(self, client_id, client_secret, code, redirect_uri=None, single_channel=None): ...
99
```