0authkit

中文文档
1.0.2发布于 2026/04/26MITTypeScriptES Module零依赖

Add OAuth to any app in minutes. Bring your own credentials.

原始使用文档
文档目录11 节
  1. Project health (honest status)
  2. Install
  3. 60-second integration (server-side)
  4. 1) Create kit
  5. 2) Redirect user
  6. 3) Handle callback
  7. Best-practice callback (recommended)
  8. Entry points
  9. Providers
  10. Security notes
  11. Output shape

0AuthKit

Add OAuth to apps fast, with minimal boilerplate.

0AuthKit gives you a small TypeScript SDK for Google + GitHub OAuth flows.

Project health (honest status)

  • ✅ Build passes
  • ✅ Basic automated tests (core auth + callback security checks)
  • ✅ Core flow implemented: auth URL, token exchange, profile fetch
  • ✅ State validation support (pass expectedState in callback)

So: solid mini-hack foundation, but add tests before calling it production-grade.


Install

npm install 0authkit

60-second integration (server-side)

1) Create kit

import { OAuthKit } from '0authkit'

const kit = new OAuthKit({
  provider: 'google',
  clientId: process.env.GOOGLE_CLIENT_ID!,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
  redirectUri: 'http://localhost:3000/auth/callback',
})

2) Redirect user

app.get('/auth/google', async (req, res) => {
  const { url, state, codeVerifier } = await kit.getAuthUrl()
  req.session.oauthState = state
  req.session.oauthCodeVerifier = codeVerifier
  res.redirect(url)
})

3) Handle callback

app.get('/auth/callback', async (req, res) => {
  const result = await kit.handleCallback(
    String(req.query.code),
    String(req.query.state)
  )

  // Recommended: use server functional API for explicit state/codeVerifier checks
  // import { handleCallback } from '0authkit/server'
  // const result = await handleCallback({
  //   provider: 'google',
  //   code: String(req.query.code),
  //   state: String(req.query.state),
  //   expectedState: req.session.oauthState,
  //   codeVerifier: req.session.oauthCodeVerifier,
  //   clientId: process.env.GOOGLE_CLIENT_ID!,
  //   clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
  //   redirectUri: 'http://localhost:3000/auth/callback',
  // })

  res.json(result.profile)
})

Use 0authkit/server so you can validate state and PKCE verifier explicitly.

import { getAuthUrl, handleCallback } from '0authkit/server'

app.get('/auth/google', async (req, res) => {
  const { url, state, codeVerifier } = await getAuthUrl({
    provider: 'google',
    clientId: process.env.GOOGLE_CLIENT_ID!,
    redirectUri: 'http://localhost:3000/auth/callback',
  })

  req.session.oauthState = state
  req.session.oauthCodeVerifier = codeVerifier
  res.redirect(url)
})

app.get('/auth/callback', async (req, res) => {
  const result = await handleCallback({
    provider: 'google',
    code: String(req.query.code),
    state: String(req.query.state),
    expectedState: req.session.oauthState,
    codeVerifier: req.session.oauthCodeVerifier,
    clientId: process.env.GOOGLE_CLIENT_ID!,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
    redirectUri: 'http://localhost:3000/auth/callback',
  })

  res.json(result.profile)
})

Entry points

ImportUse
0authkitClass-based server API
0authkit/serverFunctional server API (getAuthUrl, handleCallback)
0authkit/clientClient-safe getAuthUrl only

Providers

ProviderStatusPKCE
Google✅✅
GitHub✅❌

Security notes

  • Keep clientSecret on server only.
  • Always persist + validate state (expectedState).
  • For PKCE providers, persist + reuse codeVerifier.
  • Use HTTPS in production.

Output shape

result.tokens  // { accessToken, refreshToken?, expiresIn?, tokenType, scope? }
result.profile // { id, email, name, avatar, raw }

Built by thejamesnick

版本与发布记录

0authkit 共发布 3 个版本,首次发布于 2026/04/25;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.0.2latest2026/04/266 个月前
1.0.12026/04/266 个月前
1.0.02026/04/256 个月前

关于 0authkit 的常见问题

0authkit 是什么?

在几分钟内将OAuth添加到任何应用程序。带上你自己的证件。

如何安装 0authkit?

在项目目录运行 npm install 0authkit,或使用 pnpm add / yarn add / bun add。

0authkit 支持 TypeScript 吗?

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

0authkit 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

0authkit 需要什么版本的 Node.js?

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

0authkit 可以商用吗?

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

0authkit 还在维护吗?

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