Expand description
Google OAuth for Bothy apps that run their own sign-in: the CLI, the Python binding, embedded agents.
The core crate never does OAuth; it asks an AccessTokenProvider for tokens. This crate
provides one (RefreshingTokens) plus the flows to get the long-lived grant behind it:
a browser sign-in with a loopback redirect and PKCE (loopback_login), and the device
flow for machines without a browser (device_login). TokenStore keeps the grant in
the OS keyring or a file readable only by the user.
Tokens and client secrets never appear in Debug output or error messages.
Structs§
- Client
- An OAuth client of the app’s Google Cloud project.
- Device
Code - What the user must do to approve a device sign-in.
- Grant
- A long-lived grant: the refresh token and the scopes it covers.
- Refreshing
Tokens - Fresh access tokens from a grant, cached until a minute before they expire.
- Token
Store - Keeps a grant in the OS keyring, or in a
0600file where there is none (headless Linux without a Secret Service).BOTHY_TOKEN_STORE=file, orTokenStore::file_only, uses only the file.
Enums§
- Location
- Where
TokenStore::saveput the grant.
Constants§
- SCOPE_
APPDATA - The hidden per-app folder (
appDataFolder). Not available through the device flow. - SCOPE_
FILE - Files the app created, such as the visible
Bothy/<name>folders.
Traits§
- Access
Token Provider - Supplies OAuth access tokens to a backend.
Functions§
- device_
login - Signs in on a machine without a browser: the user enters a code on another device.
Google allows only
drive.filehere (it rejectsdrive.appdatain this flow). - http
- The HTTP client for Google’s OAuth endpoints (rustls with ring).
- loopback_
login - Signs in through the browser: a loopback redirect to 127.0.0.1 with PKCE.
- refresh
- Exchanges a refresh token for an access token:
(token, lifetime). - revoke
- Revokes a refresh token at Google. Google revokes per Cloud project: every device of the
user signed in with this project is signed out, so apps should usually only forget the
token locally (
TokenStore::clear). - write_
private - Writes
bytestopathatomically, readable only by the user (mode0600on Unix).