Skip to content

Fix x-cli me bookmarks by adding oauth2 login flow#5

Open
alexg0 wants to merge 4 commits intoInfatoshi:mainfrom
alexg0:oauth2
Open

Fix x-cli me bookmarks by adding oauth2 login flow#5
alexg0 wants to merge 4 commits intoInfatoshi:mainfrom
alexg0:oauth2

Conversation

@alexg0
Copy link

@alexg0 alexg0 commented Feb 18, 2026

Added following commands:

  • x-cli auth login
  • x-cli auth logout

This requires additional ENV variables

@alexg0
Copy link
Author

alexg0 commented Feb 18, 2026

This fixes #4.

Move rotating OAuth2 token state (access/refresh/expiry) out of ~/.config/x-cli/.env into ~/.config/x-cli/.env.auth2 while keeping static OAuth and app config in .env.

Implementation details:

- add get_config_auth2_env_path() and load order that overlays .env.auth2 over .env

- auto-migrate legacy token keys from .env -> .env.auth2

- make migration best-effort so commands do not fail when .env.auth2 is not writable

- persist/clear OAuth2 tokens from auth login/logout and refresh flows in .env.auth2

- update docs for static vs mutable env files and migration behavior

- add tests for env precedence, migration, and unwritable destination fallback
Consolidate repeated OAuth2 request, URL query, and user-id plumbing across API helpers and CLI command handlers while preserving existing behavior.

What changed:

- oauth2.py: split legacy token migration into focused read/write/remove helpers and simplify orchestrating flow.

- api.py: add shared _request, _query_url, and _get_user_id helpers; route bookmark and related endpoints through common logic.

- cli.py: add helper wrappers for repeated command glue (output formatting, tweet-id resolution, identity lookup, OAuth2 status lines).

Why:

- Reduce duplicate code and branching complexity in the OAuth2 branch.

- Make bookmark-oriented OAuth2 login/usage paths easier to maintain.

Verification:

- UV_CACHE_DIR=.uv-cache uv run ruff check

- UV_CACHE_DIR=.uv-cache uv run pytest -q (51 passed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments