Skip to main content

Module auth

Module auth 

Source
Expand description

Google sign-in: authorization code + PKCE on a loopback redirect, token exchange and refresh, and an access-token source for crate::GmailProvider.

pidge cannot ship a Google OAuth client for everyone (gmail.modify is a restricted scope), so whoever runs pidge brings their own: a “Desktop app” client locally (PIDGE_GOOGLE_CLIENT_ID / PIDGE_GOOGLE_CLIENT_SECRET), a “Web application” client when hosted. Google treats a desktop client’s secret as non-confidential, but its token endpoint still wants it.

Token persistence reuses pidge-client’s TokenBackend seam, so the CLI’s keychain/file store (pidge_client::auth::LocalBackend) and the hosted server’s secret store both work unchanged.

Structs§

GoogleAuth
Access tokens for one Google account, refreshed on demand and saved back through backend.
GoogleOAuthConfig
A Google OAuth client.

Constants§

GOOGLE_AUTH_BASE
Google’s authorization endpoint.
GOOGLE_TOKEN_URL
Google’s token endpoint.
SCOPES
The scopes pidge asks Google for, space separated.

Functions§

authorize_url
The URL to send the user’s browser to. challenge is the PKCE S256 challenge, state the CSRF nonce. access_type=offline plus prompt=consent makes Google return a refresh token every time.
exchange_code
Exchange an authorization code for tokens; also returns the account’s address from the id token.
refresh
Refresh tokens. Google usually leaves refresh_token out of a refresh response: the old one stays valid and is kept.
run_loopback_flow
The whole local sign-in: listen on 127.0.0.1:<random port>, hand the authorization URL to on_open (open a browser, print it), wait up to five minutes for Google’s redirect, check state, exchange the code.