Shared auth runtime for OpenClaw skills
Go to file
ywkj ff8e74e0aa fix: 改用 shell wrapper 代替 bun compile(bun 1.x compile 有 bug)
install.sh 生成 shell wrapper 脚本 exec bun run cli.ts,
而非 bun build --compile(生成空文件)。
auth-cli.ts 修复 HOME 环境变量缺失时 homedir() 返回空的问题。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-20 18:30:56 +08:00
dist fix: createEnvConfig() now calls loadGlobalEnv() + export functional API 2026-03-20 06:42:07 +08:00
src fix: 改用 shell wrapper 代替 bun compile(bun 1.x compile 有 bug) 2026-03-20 18:30:56 +08:00
.gitignore fix: 改用 shell wrapper 代替 bun compile(bun 1.x compile 有 bug) 2026-03-20 18:30:56 +08:00
README.md feat: initial auth-runtime module 2026-03-12 07:33:43 +08:00
bun.lock feat: initial auth-runtime module 2026-03-12 07:33:43 +08:00
install.sh fix: 改用 shell wrapper 代替 bun compile(bun 1.x compile 有 bug) 2026-03-20 18:30:56 +08:00
package.json fix: 改用 shell wrapper 代替 bun compile(bun 1.x compile 有 bug) 2026-03-20 18:30:56 +08:00
tsconfig.json feat: initial auth-runtime module 2026-03-12 07:33:43 +08:00

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