Shared auth runtime for OpenClaw skills
Go to file
ywkj 0d72c189b3
Build and Release auth-rt / release (push) Successful in 1m50s Details
feat: 模块级 session ID 自动生成
- auth-cli.ts 加载时自动生成 SKILL_SESSION_ID(格式: skill-YYYYMMDD-HHMMSS-xxxx)
- 优先级: 已有 SKILL_SESSION_ID env > 自动生成
- 所有 import 此文件的 skill 自动获得 session 追踪

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-26 19:00:37 +08:00
.forgejo/workflows fix: go.mod 降级到 1.22,CI 加 GOTOOLCHAIN=local 2026-03-20 21:24:22 +08:00
cli fix: go.mod 降级到 1.22,CI 加 GOTOOLCHAIN=local 2026-03-20 21:24:22 +08:00
dist fix: createEnvConfig() now calls loadGlobalEnv() + export functional API 2026-03-20 06:42:07 +08:00
src feat: 模块级 session ID 自动生成 2026-04-26 19:00:37 +08:00
.gitignore feat: Go 重写 auth-rt CLI,真正的零依赖二进制 2026-03-20 20:51:45 +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 feat: Go 重写 auth-rt CLI,真正的零依赖二进制 2026-03-20 20:51:45 +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