scorpiox-bot-plugin-claudecode-login
←mock_refresh.shbash
38 lines · 1 KBHEADBlameDownload
1#!/bin/sh
2# tests/mock_refresh.sh - stand-in for scorpiox-claudecode-refreshtoken.
3#
4# Mirrors the production program's argument shape (--credentials-file <path>
5# [--force]) and its behaviour: it rewrites the credentials file in place with a
6# freshly minted access token and a new expiresAt, and prints human text (which
7# may include token material) on stdout. The plugin must never forward that.
8#
9# MOCK_REFRESH_FAIL=1 exercises the failure path where the file is untouched.
10
11CREDS=""
12FORCE=0
13while [ $# -gt 0 ]; do
14 case "$1" in
15 --credentials-file) shift; CREDS="${1:-}" ;;
16 --force|-f) FORCE=1 ;;
17 esac
18 shift
19done
20[ -z "$CREDS" ] && CREDS="${CLAUDE_CREDS_PATH:-/nonexistent}"
21
22if [ "$MOCK_REFRESH_FAIL" = "1" ]; then
23 printf 'error: no refreshToken found in credentials\n' >&2
24 exit 1
25fi
26if [ ! -f "$CREDS" ]; then
27 printf 'error: cannot read %s\n' "$CREDS" >&2
28 exit 1
29fi
30
31_now=$(date +%s)
32_exp=$(( (_now + 28800) * 1000 ))
33printf 'Claude OAuth Token Auto-Refresh Tool\n\n'
34printf 'Found Claude config: %s\n' "$CREDS"
35printf 'Refreshing OAuth token (force=%s)\n' "$FORCE"
36printf '{"claudeAiOauth":{"accessToken":"sk-ant-oat01-MOCK-REFRESHED-MUST-NOT-LEAK","refreshToken":"sk-ant-ort01-MOCK-REFRESHED","expiresAt":%s,"scopes":["user:profile","user:inference"],"subscriptionType":"pro"}}\n' "$_exp" > "$CREDS"
37printf 'Token refresh successful\n'
38exit 0