|
1 | 1 | # Authentication |
2 | 2 |
|
3 | | -This module provides functions to help authenticate with Todoist using the OAuth protocol. |
| 3 | +This module provides helpers to authenticate with Todoist using OAuth. |
4 | 4 |
|
5 | 5 | ## Quick start |
6 | 6 |
|
7 | 7 | ```python |
8 | 8 | import uuid |
9 | | -from todoist_api_python.authentication import get_access_token, get_authentication_url |
| 9 | + |
| 10 | +from todoist_api_python.authentication import get_auth_token, get_authentication_url |
10 | 11 |
|
11 | 12 | # 1. Generate a random state |
12 | | -state = uuid.uuid4() |
| 13 | +state = str(uuid.uuid4()) |
13 | 14 |
|
14 | | -# 2. Get authorization url |
| 15 | +# 2. Build the authorization URL |
15 | 16 | url = get_authentication_url( |
16 | 17 | client_id="YOUR_CLIENT_ID", |
17 | 18 | scopes=["data:read", "task:add"], |
18 | | - state=uuid.uuid4() |
| 19 | + state=state, |
19 | 20 | ) |
20 | 21 |
|
21 | | -# 3.Redirect user to url |
22 | | -# 4. Handle OAuth callback and get code |
| 22 | +# 3. Redirect the user to `url` |
| 23 | +# 4. Handle the OAuth callback and obtain the auth code |
23 | 24 | code = "CODE_YOU_OBTAINED" |
24 | 25 |
|
25 | | -# 5. Exchange code for access token |
26 | | -auth_result = get_access_token( |
| 26 | +# 5. Exchange code for an access token |
| 27 | +auth_result = get_auth_token( |
27 | 28 | client_id="YOUR_CLIENT_ID", |
28 | 29 | client_secret="YOUR_CLIENT_SECRET", |
29 | 30 | code=code, |
30 | 31 | ) |
31 | 32 |
|
32 | 33 | # 6. Ensure state is consistent, and done! |
33 | | -assert(auth_result.state == state) |
| 34 | +assert auth_result.state == state |
34 | 35 | access_token = auth_result.access_token |
35 | 36 | ``` |
36 | 37 |
|
|
0 commit comments