This project supports two local Gmail OAuth patterns:
- the Python helper flow that stores
token.jsonlocally - the React frontend flow that redirects back to the frontend login page and exchanges the code through the FastAPI backend
- Open the Google Cloud Console.
- Create a new project or choose an existing one.
- In the selected project, open APIs & Services.
- Enable Gmail API.
- Open Google Auth Platform or APIs & Services > Credentials.
- Configure the OAuth consent screen if this is the first OAuth client in the project.
- Create a new OAuth client ID.
- If you plan to use the Python helper flow directly, choose Desktop app.
- If you plan to connect Gmail from the React frontend, choose Web application and add your frontend login URL as an authorized redirect URI.
- Download the client secrets JSON file.
Typical local frontend redirect URIs:
http://127.0.0.1:4173/loginhttp://localhost:4173/loginhttp://127.0.0.1:5173/loginhttp://localhost:5173/login
Store the downloaded file outside the repo or in a private local app-data path.
Example:
mkdir -p ~/.config/inboxanchor
mv ~/Downloads/client_secret_*.json ~/.config/inboxanchor/credentials.jsonThe first run opens a browser for consent and creates token.json.
Example:
from inboxanchor.connectors.oauth_flow import get_credentials
get_credentials(
credentials_path="/Users/you/.config/inboxanchor/credentials.json",
token_path="/Users/you/.config/inboxanchor/token.json",
scopes=["https://www.googleapis.com/auth/gmail.modify"],
)On later runs, the token is refreshed silently when possible.
If you are using the React frontend instead of the Python helper, InboxAnchor will redirect back to the frontend login page and exchange the code through the backend automatically.
InboxAnchor uses:
https://www.googleapis.com/auth/gmail.modify
This scope is required because the app reads messages, applies labels, removes inbox state, marks messages as read, and moves messages to trash when the human approval flow allows it.
Set the credential paths in your local environment:
export GMAIL_CREDENTIALS_PATH="/Users/you/.config/inboxanchor/credentials.json"
export GMAIL_TOKEN_PATH="/Users/you/.config/inboxanchor/token.json"Minimal code example:
from inboxanchor.connectors.gmail_client import GmailClient
from inboxanchor.connectors.gmail_transport import GoogleAPITransport
client = GmailClient(
transport=GoogleAPITransport(
credentials_path="/Users/you/.config/inboxanchor/credentials.json",
token_path="/Users/you/.config/inboxanchor/token.json",
)
)credentials.jsonandtoken.jsonmust stay out of version control.- They should live in private local paths or injected runtime mounts.
- The repo
.gitignorealready excludes.env,*.db, and other local artifacts. Keep OAuth credential files outside the repo whenever possible.