feat: add auto token refresh for ALL platforms

New qwen-token-refresh.sh script provides automatic token refresh
for OpenClaw, NanoBot, PicoClaw, NanoClaw (ZeroClaw has native support).

Features:
- Check token status and expiry
- Auto-refresh when < 5 min remaining
- Background daemon mode (5 min intervals)
- Systemd service installation
- Updates both oauth_creds.json and .env file

Usage:
  ./scripts/qwen-token-refresh.sh --status   # Check status
  ./scripts/qwen-token-refresh.sh            # Refresh if needed
  ./scripts/qwen-token-refresh.sh --daemon   # Background daemon
  ./scripts/qwen-token-refresh.sh --install  # Systemd service

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Claude Code
2026-02-22 05:18:50 -05:00
Unverified
parent e21168c6ec
commit 9b46db629e
4 changed files with 421 additions and 11 deletions

View File

@@ -233,14 +233,14 @@ zeroclaw gateway
│ • Treats Qwen API as OpenAI-compatible endpoint │
│ • Extract access_token and use as OPENAI_API_KEY │
│ • Set OPENAI_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1 │
│ • Manual re-export needed when token expires
│ • Use qwen-token-refresh.sh for automatic refresh
│ │
│ COMPARISON: │
│ ┌─────────────────┬────────────────┬─────────────────────┐ │
│ │ Feature │ Native │ OpenAI-Compatible │ │
│ ├─────────────────┼────────────────┼─────────────────────┤ │
│ │ Token Refresh │ ✅ Automatic │ ❌ Manual │ │
│ │ Token Expiry │ ✅ Handled │ ⚠️ Re-export needed│ │
│ │ Token Refresh │ ✅ Automatic │ ✅ Script/Daemon │ │
│ │ Token Expiry │ ✅ Handled │ ✅ Handled │ │
│ │ Platforms │ ZeroClaw only │ All others │ │
│ │ Config File │ ~/.qwen/oauth_creds.json │ env vars │ │
│ └─────────────────┴────────────────┴─────────────────────┘ │
@@ -268,6 +268,29 @@ Qwen Code stores OAuth credentials in `~/.qwen/oauth_creds.json`:
| `refresh_token` | Used to get new access_token when expired |
| `expiry_date` | Unix timestamp when access_token expires |
### Auto Token Refresh for ALL Platforms
```bash
# Check token status
./scripts/qwen-token-refresh.sh --status
# Refresh if expired (5 min buffer)
./scripts/qwen-token-refresh.sh
# Run as background daemon
./scripts/qwen-token-refresh.sh --daemon
# Install as systemd service (auto-start)
./scripts/qwen-token-refresh.sh --install
systemctl --user enable --now qwen-token-refresh
```
The refresh script:
- Checks token expiry every 5 minutes
- Refreshes automatically when < 5 min remaining
- Updates `~/.qwen/oauth_creds.json` and `~/.qwen/.env`
- Works for ALL platforms (OpenClaw, NanoBot, PicoClaw, NanoClaw)
### API Endpoints
| Endpoint | URL |
@@ -575,11 +598,12 @@ GOOGLE_CLOUD_LOCATION=us-central1
```
skills/claw-setup/
├── SKILL.md # Skill definition (this file's source)
├── README.md # This documentation
├── SKILL.md # Skill definition (this file's source)
├── README.md # This documentation
└── scripts/
├── import-qwen-oauth.sh # Import FREE Qwen OAuth to any platform
── fetch-models.sh # Fetch models from all providers
├── import-qwen-oauth.sh # Import FREE Qwen OAuth to any platform
── qwen-token-refresh.sh # Auto-refresh tokens (daemon/systemd)
└── fetch-models.sh # Fetch models from all providers
```
---
@@ -598,11 +622,16 @@ find ~/.qwen -name "*.json"
### Token Expired
```bash
# Tokens auto-refresh in Qwen Code
qwen -p "refresh"
# Option 1: Use auto-refresh script
./scripts/qwen-token-refresh.sh
# Re-export
# Option 2: Manual re-auth
qwen --auth-type qwen-oauth -p "test"
source ~/.qwen/.env
# Option 3: Install systemd service for auto-refresh
./scripts/qwen-token-refresh.sh --install
systemctl --user enable --now qwen-token-refresh
```
### API Errors