Authentication
This module provides helpers to authenticate with Todoist using OAuth.
Quick start
import uuid
from todoist_api_python.authentication import get_auth_token, get_authentication_url
# 1. Generate a random state
state = str(uuid.uuid4())
# 2. Build the authorization URL
url = get_authentication_url(
client_id="YOUR_CLIENT_ID",
scopes=["data:read", "task:add"],
state=state,
)
# 3. Redirect the user to `url`
# 4. Handle the OAuth callback and obtain the auth code
code = "CODE_YOU_OBTAINED"
# 5. Exchange code for an access token
auth_result = get_auth_token(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
code=code,
)
# 6. Ensure state is consistent, and done!
assert auth_result.state == state
access_token = auth_result.access_token
For detailed implementation steps and security considerations, refer to the Todoist OAuth documentation.
get_auth_token(client_id, client_secret, code, client=None)
Get access token using provided client ID, client secret, and auth code.
Source code in todoist_api_python/authentication.py
get_auth_token_async(client_id, client_secret, code, client=None)
async
Get access token asynchronously.
Source code in todoist_api_python/authentication.py
get_authentication_url(client_id, scopes, state)
Get authorization URL to initiate OAuth flow.
Source code in todoist_api_python/authentication.py
revoke_auth_token(client_id, client_secret, token, client=None)
Revoke an access token.
Source code in todoist_api_python/authentication.py
revoke_auth_token_async(client_id, client_secret, token, client=None)
async
Revoke an access token asynchronously.