Credentials and authorization
gclientid stores OAuth client and authorized-user token JSON files under $XDG_CONFIG_HOME/gclientid/ (normally ~/.config/gclientid/).
Loading and refreshing tokens
oauth_creds loads a stored token by account or file path, refreshes it asynchronously when expired, and optionally triggers browser re-authorization when scopes are missing or Google rejects the refresh. refresh_creds refreshes an existing credentials object on a worker thread and saves the updated token.
creds = await oauth_creds(account='me@example.com', scopes=['https://www.googleapis.com/auth/drive'])oauth_creds
async def oauth_creds(
token_path=None, scopes=None, account=None, internal:bool=False, desktop:bool=False, reauth=None
):OAuth creds from a token file, or from the stored token for account (internal and desktop select the client).
reauth runs gclientid-auth in the configured browser when the token is missing, lacks scopes, or can no longer be refreshed; None follows the store’s reauth setting.
@allow is applied at definition so every imported copy is the sandbox-tracked wrapper: an expired token is refreshed on a worker thread, where only a tracked call’s context survives the audit.
refresh_creds
async def refresh_creds(
creds, token_path=None, reauth=None
):Refresh creds without blocking the event loop, saving to token_path (default: the file they were loaded from).
When Google rejects the refresh, reauth (None: the store’s setting) runs one gclientid-auth instead of raising.
logout
async def logout(
token_path=None, account=None, internal:bool=False, desktop:bool=False
):Revoke and remove the token selected by account (with internal/desktop) or token_path; no-op if it does not exist
token_has_scopes
def token_has_scopes(
token_path, scopes
):Whether the authorized-user token file at token_path includes all of scopes
Helpers
token_file
def token_file(
account:str, # Authorized Google account email
internal:bool=False, # Token for the Internal-audience client?
desktop:bool=False, # Token for the Desktop client?
output:pathlib._local.Path=None, # Credential directory; $XDG_CONFIG_HOME/gclientid if omitted
):Path of the stored authorized-user token JSON for account
client_file
def client_file(
internal:bool=False, # The Internal-audience client?
desktop:bool=False, # The Desktop client instead of the Web client?
output:pathlib._local.Path=None, # Credential directory; $XDG_CONFIG_HOME/gclientid if omitted
):Path of the stored OAuth client JSON
reauth_cmd
def reauth_cmd(
token_path
):The gclientid-auth command that recreates the token stored at token_path
token_name
def token_name(
token_path
):The (account, internal, desktop) a stored token’s filename encodes; account is ’’ for a file named some other way