Skip to content

Conversation

@konard
Copy link
Contributor

@konard konard commented Dec 9, 2025

Summary

Implements Qwen Coder OAuth authentication support for the agent CLI, based on the qwen-auth-opencode reference implementation.

Authentication Methods

Both Qwen Coder and Alibaba provider menu items now support two authentication methods:

  1. Qwen Coder OAuth (Free Tier)

    • Uses device flow authentication compatible with chat.qwen.ai
    • 2,000 free requests per day
    • Automatic browser opening in GUI environments
    • Manual code entry for headless/SSH environments
  2. DashScope API Key

    • Pay-as-you-go authentication via DashScope
    • Supports both China and International regions
    • API key validation (must start with 'sk-')

Usage

# Interactive login (shows provider selection)
agent auth login

# Check authentication status
agent auth status

# Remove credentials
agent auth logout

Implementation Details

  • Added Qwen OAuth plugin to js/src/auth/plugins.ts
  • Uses OAuth 2.0 Device Authorization Grant (RFC 8628)
  • PKCE (S256) for secure authorization
  • Token polling with configurable intervals
  • Credentials stored in standard auth.json format

Test plan

  • Run agent auth login and select "Qwen Coder" → "Qwen Coder OAuth"
  • Verify device code flow opens browser or shows manual instructions
  • Run agent auth login and select "Alibaba" → "DashScope API Key"
  • Verify API key validation works correctly
  • Run agent auth status to verify credentials are stored
  • Run agent auth logout to verify credentials can be removed

Closes #24


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #24
@konard konard self-assigned this Dec 9, 2025
Research findings comparing OAuth implementations across CLI agentic tools:
- Qwen Code CLI: Device Code OAuth flow with qwen.ai
- Claude Code: PKCE OAuth with Anthropic
- Gemini CLI: Google OAuth with web-based and user-code flows
- OpenCode: Plugin-based auth system supporting multiple providers

Includes implementation proposals for @link-assistant/agent:
- Option 1: Full Device Code OAuth implementation
- Option 2: Credential reading only (minimal)
- Option 3: Plugin-style architecture
- Recommended: Hybrid phased approach

Documents credential storage locations for compatibility:
- Primary: ~/.qwen/oauth_creds.json (Qwen Code CLI)
- Fallback: ~/.agent/qwen/ (our app folder)

Closes research phase of #24

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Qwen Coder oAuth support Research: Qwen Coder OAuth support Dec 9, 2025
@konard konard marked this pull request as ready for review December 9, 2025 04:53
@konard
Copy link
Contributor Author

konard commented Dec 9, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $4.272865 USD
  • Calculated by Anthropic: $3.669694 USD
  • Difference: $-0.603171 (-14.12%)
    📎 Log file uploaded as GitHub Gist (558KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Jan 26, 2026

https://github.com/lion-lef/qwen-auth-opencode - here we have working example implementation, please get latest changes from default branch, and integrate it with our agent auth login, so we have not only API key for Alibaba, but also for the subscription, and also we should have separate Qwen Coder menu item alias.

@konard konard marked this pull request as draft January 26, 2026 08:42
@konard
Copy link
Contributor Author

konard commented Jan 26, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-26T08:42:19.400Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

Implements Qwen OAuth 2.0 Device Flow for the agent CLI, providing:

- New `agent auth login [qwen|alibaba]` command with OAuth and API key support
- Qwen Device Code flow compatible with chat.qwen.ai OAuth endpoints
- Token refresh handling with automatic renewal before expiration
- New qwen-coder provider with coder-model and vision-model (free tier)
- Support for both OAuth (2,000 free requests/day) and DashScope API key auth

Auth commands:
- `agent auth login` - Interactive provider selection
- `agent auth login qwen` - Qwen OAuth login (free tier)
- `agent auth login alibaba` - DashScope API key login
- `agent auth logout [provider]` - Logout from provider
- `agent auth status` - Show authentication status

Fixes #24

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title Research: Qwen Coder OAuth support feat: Add Qwen Coder OAuth authentication support Jan 26, 2026
@konard konard marked this pull request as ready for review January 26, 2026 08:49
@konard
Copy link
Contributor Author

konard commented Jan 26, 2026

🤖 Solution Draft Log

Implemented Qwen Coder OAuth authentication support based on the qwen-auth-opencode reference implementation.

What was implemented:

  1. New agent auth command with login/logout/status subcommands
  2. Qwen OAuth Device Flow - compatible with chat.qwen.ai OAuth endpoints (same as qwen-code CLI)
  3. New qwen-coder provider with OAuth-authenticated models (coder-model, vision-model)
  4. Both OAuth and API Key authentication options:
    • agent auth login qwen - OAuth free tier (2,000 requests/day)
    • agent auth login alibaba - DashScope API key (pay-as-you-go)

Files changed:

  • src/qwen/oauth.ts - Qwen OAuth Device Flow implementation
  • src/cli/cmd/auth.ts - Auth CLI commands
  • src/provider/provider.ts - Qwen-coder provider integration
  • src/index.js - Register auth command

Usage:

# Interactive login
agent auth login

# Qwen OAuth (free tier)
agent auth login qwen

# Check status
agent auth status

# Logout
agent auth logout qwen

Working session completed.

@konard
Copy link
Contributor Author

konard commented Jan 26, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Jan 26, 2026

As I understand it, free tier + subscription should be available as both Qwen Coder and Alibaba menu items.

Resolve conflicts, ensure all changes are correct, consistent and fully meet all discussed requirements.

@konard konard marked this pull request as draft January 26, 2026 10:12
@konard
Copy link
Contributor Author

konard commented Jan 26, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-26T10:12:13.854Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

- Resolve merge conflicts from main branch restructure (js/ directory)
- Add Qwen Coder OAuth (device flow) plugin for free tier authentication
- Add Alibaba DashScope API key authentication support
- Both menu items (Qwen Coder and Alibaba) support:
  - OAuth device flow (2,000 free requests/day via chat.qwen.ai)
  - DashScope API key (pay-as-you-go, China and International regions)
- Remove old src/ files that moved to js/src/
- Remove old Qwen OAuth research documentation

Based on qwen-auth-opencode reference implementation:
https://github.com/lion-lef/qwen-auth-opencode

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review January 26, 2026 10:17
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard
Copy link
Contributor Author

konard commented Jan 26, 2026

🤖 Implementation Complete

All CI checks are now passing. The implementation includes:

Features Added:

  1. QwenPlugin (qwen-coder provider) - available in auth login menu

    • Qwen Coder OAuth (Free Tier) - device flow with PKCE
    • DashScope API Key (Pay-as-you-go) - China and International regions
  2. AlibabaPlugin (alibaba provider) - available in auth login menu

    • Same authentication methods as QwenPlugin (both aliases work)

OAuth Implementation Details:

  • Uses device authorization grant (RFC 8628) with PKCE
  • Auto-opens browser for authorization when possible
  • Polling for token completion with configurable intervals
  • Automatic access token refresh support
  • Free tier cost zeroing for OAuth users

API Key Support:

  • China region: dashscope.aliyuncs.com
  • International region: dashscope-intl.aliyuncs.com
  • API key validation (must start with sk-)

Files Changed:

  • js/src/auth/plugins.ts - Added ~300 lines for Qwen/Alibaba auth plugins
  • js/.changeset/add-qwen-oauth-support.md - Changeset for version bump

Usage:

# Interactive login (select Qwen Coder or Alibaba from menu)
agent auth login

# Check status
agent auth status

# Logout
agent auth logout

Both "Qwen Coder" and "Alibaba" menu items now support:

  • Free tier OAuth authentication (subscription)
  • DashScope API key authentication (pay-as-you-go)

Working session complete. Ready for review.

@konard
Copy link
Contributor Author

konard commented Jan 26, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $9.316488 USD
  • Calculated by Anthropic: $5.437628 USD
  • Difference: $-3.878861 (-41.63%)
    📎 Log file uploaded as Gist (1430KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

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.

Qwen Coder oAuth support

2 participants