Skip to content

feat(cli): add minimax-oauth provider with PKCE browser flow (salvage #15203) - #15419

Closed
teknium1 wants to merge 5 commits into
mainfrom
hermes/hermes-6c37b3dd
Closed

feat(cli): add minimax-oauth provider with PKCE browser flow (salvage #15203)#15419
teknium1 wants to merge 5 commits into
mainfrom
hermes/hermes-6c37b3dd

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvages #15203 onto current main.

Adds minimax-oauth as a first-class provider with a PKCE browser OAuth flow against MiniMax's platform (api.minimax.io/oauth/code + /oauth/token). Reuses the existing anthropic_messages api_mode against /anthropic — no new adapter, no new api_mode — since agent/anthropic_adapter.py already supports Bearer-token auth for MiniMax endpoints.

  • Provider id: minimax-oauth (aliases: minimax-portal, minimax-global, minimax_oauth)
  • PKCE S256, urn:ietf:params:oauth:grant-type:user_code grant, state validation, poll-with-deadline
  • Region flag (global / cn) selects between api.minimax.io and api.minimaxi.com
  • Tokens persisted in the existing auth store, standard refresh_token grant with invalid_grant / reuse detection
  • Supports MiniMax-M2.7 and MiniMax-M2.7-highspeed; highspeed wired as auxiliary model

Leaves existing API-key minimax / minimax-cn providers untouched (explicit non-goal).

Changes vs. #15203

  • 4 original commits cherry-picked unchanged with @amanning3390 authorship preserved
  • scripts/release.py AUTHOR_MAP: add amanning3390 mapping (CI gate)

Validation

Targeted tests green (238 passed in 5.66s):

  • tests/test_minimax_oauth.py — OAuth flow, refresh, token store (15 tests)
  • tests/hermes_cli/test_api_key_providers.py — provider registry + aliases
  • tests/hermes_cli/test_runtime_provider_resolution.py — runtime branch

E2E verified with isolated HERMES_HOME + mock auth store:

  • resolve_runtime_provider(requested="minimax-oauth") returns api_mode=anthropic_messages, base_url=https://api.minimax.io/anthropic, bearer token, source=oauth
  • All 3 aliases (minimax-portal, minimax-global, minimax_oauth) route to minimax-oauth
  • get_minimax_oauth_auth_status() reflects login/logout state for hermes doctor
  • Not-logged-in path raises clean AuthError with correct guidance

Attribution

Original PR #15203 by @amanning3390. Cherry-picked onto current main; @amanning3390's authorship preserved on all 4 commits via rebase-merge.

Closes #15203.

amanning3390 and others added 5 commits April 24, 2026 16:41
Add MiniMax OAuth (minimax-oauth) as a first-class provider using a
PKCE device-code flow ported from openclaw/extensions/minimax/oauth.ts.

Changes:
- hermes_cli/auth.py:
  - Add 8 MINIMAX_OAUTH_* constants (client ID, scope, grant type,
    global/CN base URLs, inference URLs, refresh skew)
  - Add 'minimax-oauth' ProviderConfig to PROVIDER_REGISTRY (auth_type
    oauth_minimax) with global portal + inference base URLs and CN
    extras in the extra dict
  - Add provider aliases: minimax-portal, minimax-global, minimax_oauth
  - Implement _minimax_pkce_pair(), _minimax_request_user_code(),
    _minimax_poll_token(), _minimax_save_auth_state(),
    _minimax_oauth_login(), _refresh_minimax_oauth_state(),
    resolve_minimax_oauth_runtime_credentials(),
    get_minimax_oauth_auth_status(), _login_minimax_oauth()
  - Token refresh uses standard OAuth2 refresh_token grant; triggers
    relogin_required on invalid_grant / refresh_token_reused
- hermes_cli/runtime_provider.py:
  - Add minimax-oauth branch (after qwen-oauth) that calls
    resolve_minimax_oauth_runtime_credentials() and returns
    api_mode='anthropic_messages' with the OAuth Bearer token
- hermes_cli/auth_commands.py:
  - Add 'minimax-oauth' to _OAUTH_CAPABLE_PROVIDERS
  - Add auth_type auto-detection for oauth_minimax
  - Add provider == 'minimax-oauth' branch in auth_add_command
- hermes_cli/doctor.py:
  - Import get_minimax_oauth_auth_status
  - Add MiniMax OAuth status check in the Auth Providers section
Wire MiniMax-M2.7 and MiniMax-M2.7-highspeed into the model catalog,
CLI model picker, and agent auxiliary/metadata subsystems.

Changes:
- hermes_cli/models.py:
  - Add 'minimax-oauth' to _PROVIDER_MODELS with MiniMax-M2.7 and
    MiniMax-M2.7-highspeed
  - Add ProviderEntry('minimax-oauth', 'MiniMax (OAuth)', ...) to
    CANONICAL_PROVIDERS near existing minimax entries
  - Add aliases: minimax-portal, minimax-global, minimax_oauth in
    _PROVIDER_ALIASES
- hermes_cli/main.py:
  - Add 'minimax-oauth' to provider_labels dict
  - Insert 'minimax-oauth' into providers list in
    select_provider_and_model() near the other minimax entries
  - Add 'minimax-oauth' to --provider argparse choices
  - Add _model_flow_minimax_oauth() function: ensures login via
    _login_minimax_oauth(), resolves runtime credentials, prompts for
    model selection, saves model choice and config
  - Add dispatch elif branch for selected_provider == 'minimax-oauth'
- agent/auxiliary_client.py:
  - Add 'minimax-oauth': 'MiniMax-M2.7-highspeed' to
    _API_KEY_PROVIDER_AUX_MODELS
  - Add 'minimax-oauth' to _ANTHROPIC_COMPAT_PROVIDERS set
- agent/model_metadata.py:
  - Add 'minimax-oauth' to _PROVIDER_PREFIXES frozenset
  - MiniMax-M2.7 context length (200_000) already covered by the
    existing 'minimax' substring match in DEFAULT_CONTEXT_LENGTHS
Add and extend tests for the minimax-oauth provider across three test
modules.

New file: tests/test_minimax_oauth.py (15 tests)
  - test_pkce_pair_produces_valid_s256: verifies PKCE verifier/challenge
    pair produces a valid S256 hash and correct lengths
  - test_request_user_code_happy_path: mocks httpx, verifies correct
    POST parameters and response parsing
  - test_request_user_code_state_mismatch_raises: verifies CSRF guard
  - test_request_user_code_non_200_raises: verifies HTTP error handling
  - test_poll_token_pending_then_success: verifies polling loop retries
    on 'pending' and returns on 'success'
  - test_poll_token_error_raises: verifies 'error' status raises AuthError
  - test_poll_token_timeout_raises: verifies deadline expiry raises
  - test_refresh_skip_when_not_expired: verifies no HTTP call when token
    is fresh
  - test_refresh_updates_access_token: verifies new access/refresh tokens
    stored on successful refresh
  - test_refresh_reuse_triggers_relogin_required: verifies
    relogin_required=True on invalid_grant/refresh_token_reused
  - test_resolve_credentials_requires_login: verifies AuthError when no
    stored state
  - test_provider_registry_contains_minimax_oauth: PROVIDER_REGISTRY key
  - test_minimax_oauth_alias_resolves: portal/global/underscore aliases
  - test_get_minimax_oauth_auth_status_not_logged_in
  - test_get_minimax_oauth_auth_status_logged_in

Extended: tests/hermes_cli/test_runtime_provider_resolution.py
  - test_minimax_oauth_runtime_returns_anthropic_messages_mode
  - test_minimax_oauth_runtime_uses_inference_base_url

Extended: tests/hermes_cli/test_api_key_providers.py
  - TestMinimaxOAuthProvider class (8 tests) covering registry keys,
    auth_type, endpoints, client_id, aliases, CANONICAL_PROVIDERS
    listing, _PROVIDER_MODELS entries, and aux model
Add comprehensive documentation for the minimax-oauth provider.

New file: website/docs/guides/minimax-oauth.md
  - Overview table (provider ID, auth type, models, endpoints)
  - Quick start via 'hermes model'
  - Manual login via 'hermes auth add minimax-oauth'
  - --region global|cn flag reference
  - The PKCE OAuth flow explained step-by-step
  - hermes doctor output example
  - Configuration reference (config.yaml shape, region table, aliases)
  - Environment variables note: MINIMAX_API_KEY is NOT used by
    minimax-oauth (OAuth path uses browser login)
  - Models table with context length note
  - Troubleshooting section: expired token, timeout, state mismatch,
    headless/remote sessions, not logged in
  - Logout command

Updated: website/docs/getting-started/quickstart.md
  - Add MiniMax (OAuth) to provider picker table as the recommended
    path for users who want MiniMax models without an API key

Updated: website/docs/user-guide/configuration.md
  - Add 'minimax-oauth' to the auxiliary providers list
  - Add MiniMax OAuth tip callout in the providers section
  - Add minimax-oauth row to the provider table (auxiliary tasks)
  - Add MiniMax OAuth config.yaml example in Common Setups

Updated: website/docs/reference/environment-variables.md
  - Annotate MINIMAX_API_KEY, MINIMAX_BASE_URL, MINIMAX_CN_API_KEY,
    MINIMAX_CN_BASE_URL as NOT used by minimax-oauth
  - Add minimax-oauth to HERMES_INFERENCE_PROVIDER allowed values
Follow-up for cherry-picked PR #15203 (minimax-oauth provider).
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ npm lockfile hash out of date

Checked against commit 3812fd8 (PR head at check time).

The hash = "sha256-..." line in these nix files no longer matches the committed package-lock.json:

Apply the fix

  • Apply lockfile fix — tick to push a commit with the correct hashes to this PR branch
  • Or run the Nix Lockfile Fix workflow manually (pass PR #15419)
  • Or locally: nix run .#fix-lockfiles -- --apply and commit the diff

Comment thread hermes_cli/main.py Dismissed
@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists provider/minimax MiniMax (Anthropic transport) comp/cli CLI entry point, hermes_cli/, setup wizard area/auth Authentication, OAuth, credential pools labels Apr 25, 2026
@teknium1

teknium1 commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

Closing as already merged. All four commits from this branch (the PKCE flow, MiniMax-M2.7 wiring, tests, and docs) landed on main with @amanning3390's authorship preserved — plus the follow-up feat(minimax-oauth): full integration with peer OAuth providers (40a98fb) and bug fixes on top (#17425 caching, #17467 aux URL). Thanks Adam!

@teknium1 teknium1 closed this May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists provider/minimax MiniMax (Anthropic transport) type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants