← Back to Pull requests

feat(google): add token_command support for external token fetching #1221

Open
fishman opened this pull request with 154 lines diff across 2 files
View on GitHub
fishman fishman commented on Jun 14, 2026 14:45 UTC
Author

  • allows the use of https://github.com/pdobsan/oama to manage oauth tokens
  • Diff: 154 lines (+131 / -23) across 2 files Reviewer: WhyNotHugo Review duration: 248697m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.65) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.65 · 154 lines diff across 2 files
    0.65
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.86 · 4 substantive comment(s)
    0.86
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    84%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.302
    Sensitive Paths sensitive_paths
    0.065
    Real PR Conversation Timeline
    6 items
    WhyNotHugo WhyNotHugo commented on code on Jun 14, 2026 19:36 UTC
    Code Review
    docs/config.rst:1
    @@ -289,10 +278,35 @@ for reference) and the
     `BDAY <https://www.rfc-editor.org/rfc/rfc6350#section-6.2.5>`_ property is not
     synced when only partial date information is present (e.g. the year is missing).
     
    -At first run you will be asked to authorize application for Google account
    -access.
    +Authentication
    +++++++++++++++
    +
    +There are two ways to handle OAuth authentication with Google:
    +
    +1. **Built-in OAuth flow** (``token_file`` + ``client_id`` + ``client_secret``):
    +   Vdirsyncer manages the OAuth2 flow, including token storage and refresh. At
    +   first run you will be asked to authorize the application via a browser.
     
    -To use this storage type, you need to install some additional dependencies::
    +2. **External token command** (``token_command``): An external command is
    +   executed to obtain a fresh access token on demand. Vdirsyncer passes the
    +   token as a ``Bearer`` header and re-runs the command on 401 responses.
    +
    +With ``token_command``, you do not need to register a Google Cloud project or
    +install ``aiohttp-oauthlib``. Any OAuth helper that prints an access token to
    +stdout works, e.g. `oama <https://github.com/pdobsan/oama>`_::
    +
    +    [storage my_google_cal]
    +    type = "google_calendar"
    +    token_command = ["oama", "access", "my-google-account"]

    Don't you still need to register a project and provide a client_id and client_secret to oama?

    WhyNotHugo WhyNotHugo commented on code on Jun 14, 2026 19:38 UTC
    Code Review
    vdirsyncer/storage/google.py:1
    @@ -165,6 +205,30 @@ async def _init_token(self):
                 # FIXME: Ugly
                 await self._save_token(self._token)
     
    +    async def _fetch_token_via_command(self):
    +        import subprocess

    Keep this import at the top level.

    WhyNotHugo WhyNotHugo commented on code on Jun 14, 2026 19:40 UTC
    Code Review
    vdirsyncer/storage/google.py:1

    We should use the same logic and configuration style as vdirsyncer/cli/fetchparams.py for specifying the command; this implementation duplicates a lot of the existing functionality.

    WhyNotHugo WhyNotHugo requested changes on Jun 14, 2026 19:40 UTC
    Changes Requested Reviewer

    Requested changes.

    fishman fishman commented on code on Jun 15, 2026 01:59 UTC
    Code Review
    docs/config.rst:1
    @@ -289,10 +278,35 @@ for reference) and the
     `BDAY <https://www.rfc-editor.org/rfc/rfc6350#section-6.2.5>`_ property is not
     synced when only partial date information is present (e.g. the year is missing).
     
    -At first run you will be asked to authorize application for Google account
    -access.
    +Authentication
    +++++++++++++++
    +
    +There are two ways to handle OAuth authentication with Google:
    +
    +1. **Built-in OAuth flow** (``token_file`` + ``client_id`` + ``client_secret``):
    +   Vdirsyncer manages the OAuth2 flow, including token storage and refresh. At
    +   first run you will be asked to authorize the application via a browser.
     
    -To use this storage type, you need to install some additional dependencies::
    +2. **External token command** (``token_command``): An external command is
    +   executed to obtain a fresh access token on demand. Vdirsyncer passes the
    +   token as a ``Bearer`` header and re-runs the command on 401 responses.
    +
    +With ``token_command``, you do not need to register a Google Cloud project or
    +install ``aiohttp-oauthlib``. Any OAuth helper that prints an access token to
    +stdout works, e.g. `oama <https://github.com/pdobsan/oama>`_::
    +
    +    [storage my_google_cal]
    +    type = "google_calendar"
    +    token_command = ["oama", "access", "my-google-account"]

    Yeah, but not specifically for vdirsyncer. Let me rephrase it

    Reviewers
    Assignees
    fishman fishman
    Labels
    risk: low confidence: 84.9% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 64.8% (MEDIUM) · Higher = larger blast radius
    64.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 84.9% · Lower = rushed or shallow review
    84.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 9.8% · Safe to merge
    9.8%