@aooth/login-client

中文文档
0.2.6发布于 2026/11/07MITTypeScriptESM + CJS零依赖近 30 天下载 2022

Zero-dependency CLI/loopback login helper for an aoothjs authorization server (browser round-trip + PKCE, returns a token)

原始使用文档
文档目录4 节
  1. Install
  2. Use
  3. Headless / SSH
  4. Options

@aooth/login-client

Zero-dependency helper that logs a user in through their browser and hands a token back to a local process — the gh auth login pattern, for any aoothjs authorization server.

It runs the authorization-code + PKCE flow against a one-shot loopback redirect (http://127.0.0.1:<ephemeral-port>/callback), so nothing is ever copy-pasted. Built on Node built-ins (node:http, node:crypto, node:child_process) and global fetch only — no runtime dependencies.

Install

npm i @aooth/login-client   # Node >= 18

Use

import { authorize } from "@aooth/login-client";

const { accessToken, expiresIn, userId } = await authorize({
  authorizeUrl: "https://main.example.com/auth/authorize",
  tokenUrl: "https://main.example.com/auth/token",
  // clientId,                 // omit for a public/loopback client (PKCE is the binding)
  // scope: ["api"],
  // statusUrl: "https://main.example.com/auth/status",  // optional: confirm the token works
});

// send it: Authorization: Bearer <accessToken>

What it does: opens a one-shot 127.0.0.1 listener, generates state + PKCE, opens the browser to authorizeUrl, awaits the single callback, verifies state (the CSRF check), then POST tokenUrl { code, code_verifier } and returns the token. It does not crypto-validate the token — that is the server's opaque credential; TLS + PKCE + state are the binding.

Headless / SSH

await authorize({
  authorizeUrl,
  tokenUrl,
  openBrowser: false,
  onUrl: (url) => console.log(`Open this URL to sign in:\n${url}`),
});

The loopback listener still catches the callback once the user opens the URL elsewhere on the same machine.

Options

OptionDefaultNotes
authorizeUrl—the server's GET /auth/authorize
tokenUrl—the server's POST /auth/token
clientId—omit for a public/loopback client
scope—string[], joined with spaces
openBrowsertrueset false + onUrl for headless
onUrl—always called with the authorize URL (print a fallback line)
statusUrl—optional bearer-confirm GET; adopts its userId
timeoutMs300000wait for the browser callback
signal—AbortSignal to cancel (e.g. on SIGINT)

Failures throw an AuthorizeError with a .code (provider_denied · state_mismatch · exchange_failed · timeout · status_check_failed).

版本与发布记录

@aooth/login-client 共发布 85 个版本,首次发布于 2026/06/06;过去 12 个月发布了 85 个版本。

版本发布日期距今
0.2.6latest2026/11/07今天
0.2.52026/11/061 天前
0.2.42026/11/043 天前
0.2.32026/11/043 天前
0.2.22026/11/034 天前
0.2.12026/11/034 天前

关于 @aooth/login-client 的常见问题

@aooth/login-client 是什么?

Zero-dependency CLI/loopback login helper for an aoothjs authorization server (browser round-trip + PKCE, returns a token)

如何安装 @aooth/login-client?

在项目目录运行 npm install @aooth/login-client,或使用 pnpm add / yarn add / bun add。

@aooth/login-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aooth/login-client 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aooth/login-client 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aooth/login-client 可以商用吗?

@aooth/login-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aooth/login-client 的下载量有多少?

根据 npm 官方下载统计,@aooth/login-client 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,022 次,日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aooth/login-client 还在维护吗?

最新版本 0.2.6 发布于 2026/11/07(今天);至今共发布 85 个版本,其中过去 12 个月发布了 85 个;首次发布于 2026/06/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。