|
Build and Release auth-rt / build (amd64, darwin) (push) Failing after 2m53s
Details
Build and Release auth-rt / build (amd64, linux) (push) Failing after 1m16s
Details
Build and Release auth-rt / build (arm64, darwin) (push) Failing after 1m9s
Details
Build and Release auth-rt / build (arm64, linux) (push) Failing after 1m15s
Details
Build and Release auth-rt / release (push) Has been skipped
Details
- cli/ 目录:完整的 Go 实现(env/cache/auth/http/retry) - install.sh:支持本地编译和 --download 从 release 下载 - .forgejo/workflows/release.yml:CI 交叉编译 darwin/linux × amd64/arm64 - auth-cli.ts:改为调用 auth-rt 二进制(不再需要 bun/node) - 分发策略:skill install.sh 优先从 release 下载,失败则 clone + go build Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> |
||
|---|---|---|
| .forgejo/workflows | ||
| cli | ||
| dist | ||
| src | ||
| .gitignore | ||
| README.md | ||
| bun.lock | ||
| install.sh | ||
| package.json | ||
| tsconfig.json | ||
README.md
@clawd/auth-runtime
Shared TypeScript auth runtime for OpenClaw skills.
Features
- Token caching with configurable TTL
- Automatic token refresh
- Session-expired auto retry (401/403)
- Environment-based configuration
- Type-safe API
Installation
bun add file:../../_shared/auth-runtime
Usage
import {
createEnvConfig,
getAccessToken,
requestApiWithAutoRefresh,
} from '@clawd/auth-runtime';
const config = createEnvConfig();
const token = await getAccessToken(false, config);
const result = await requestApiWithAutoRefresh(
'POST',
`${config.authBase}/ecom/tasks/scrape`,
false,
config,
JSON.stringify({ url: 'https://detail.1688.com/offer/123.html' }),
token,
);
API
Functions
createEnvConfig(): EnvConfig
Create configuration from environment variables:
AUTH_BASE: Auth base URL (default: https://api-gw-test.yuanwei-lnc.com)CLIENT_KEY: Client key (required)AUTH_CACHE_DIR: Cache directory (default: /tmp/skill-auth-cache)AUTH_MIN_TTL_SEC: Minimum token TTL in seconds (default: 60)
getAccessToken(dryRun, config): Promise<string>
Get access token with caching.
refreshAccessToken(dryRun, config): Promise<string>
Refresh access token (bypass cache).
fetchSessionJson(dryRun, config): Promise<SessionResponse>
Fetch session JSON from auth endpoint.
requestApi(method, url, authToken?, body?): Promise<ApiResponse>
Make HTTP request with optional authorization header.
isRetryableSessionError(response): boolean
Check whether response likely indicates expired runtime session.
requestApiWithAutoRefresh(method, url, dryRun, config, body?, accessToken?): Promise<ApiResponse>
Call API with one automatic token refresh + retry on session-expired style errors.
Types
EnvConfig
Environment configuration.
SessionResponse
Session response from auth endpoint.
CachedTokenData
Cached token data.
HttpMethod
Supported HTTP methods.
ApiResponse
HTTP response.
Building
bun run build