@aooth/login-客户端
通过用户登录的零依赖性助手 浏览器 手举起
返回本地进程符号—— gh auth login 模式,用于任何
阿欧斯 授权服务器.
它运行授权码 + PKCE 流对一发 循环
重新定向 (http://127.0.0.1:<ephemeral-port>/callback因此,没有什么是永远
拷贝。 建于节点内置(node:http, (中文(简体) ), node:crypto, (中文(简体) ),
node:child_process)和全球 fetch 仅 -- 无运行时间依赖关系。 。 。 .
安装
npm i @aooth/login-client # Node >= 18
使用
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>
它所做的: 打开一发子弹 127.0.0.1 听器,生成 state +PKCE, + 电子计算机,
打开浏览器到 authorizeUrl等待单一的召回, 核实
state (CSRF检查),然后 POST tokenUrl { code, code_verifier } 财务报告和审定财务报表
返回符号。 没错 没有 加密验证符号——即
服务器的不透明证书; TLS + PKCE + state 是约束.
无头/ SSH
await authorize({
authorizeUrl,
tokenUrl,
openBrowser: false,
onUrl: (url) => console.log(`Open this URL to sign in:\n${url}`),
});
用户打开 URL 后, 回回收听器仍可抓取回调 在同一个机器上.
选项
| 选项 | 默认 | 页:1 |
|---|---|---|
authorizeUrl | —— 说 | 服务器的 GET /auth/authorize |
tokenUrl | —— 说 | 服务器的 POST /auth/token |
clientId | —— 说 | 省略一个公共/浏览客户端 |
scope | —— 说 | string[]空间 |
openBrowser | true | 设定 false + 键 onUrl 无头 |
onUrl | —— 说 | 总是用授权 URL 调用( 打印后退行) |
statusUrl | —— 说 | 可选择的无记名确认 GET; 采用 userId |
timeoutMs | 300000 | 等待浏览器调用 |
signal | —— 说 | AbortSignal 取消(例如在SIGINT上) |
失败投出 AuthorizeError 带有 .code
(单位:千美元)provider_denied • 妇女 state_mismatch • 妇女 exchange_failed • 妇女 timeout • 妇女
status_check_failed) (中文(简体) ).