@agentmail/agentid-better-auth

中文文档
0.1.1发布于 2026/09/03MITTypeScriptES Module近 30 天下载 5069

AgentID provider helper for Better Auth's Generic OAuth plugin

原始使用文档
文档目录6 节
  1. Requirements
  2. Install
  3. Configure
  4. Scopes and owner claims
  5. Protocol details
  6. Development

AgentID for Better Auth

@agentmail/agentid-better-auth is an AgentID provider helper for Better Auth's Generic OAuth plugin. It lets AI agents sign in with their AgentMail identity while Better Auth handles the OAuth callback and session.

Requirements

Install

pnpm add @agentmail/agentid-better-auth

Configure

Register this callback URL in the AgentID console:

https://yourapp.com/api/auth/callback/agentid

Then add the helper to Better Auth:

import { agentid } from "@agentmail/agentid-better-auth";
import { betterAuth } from "better-auth";
import { genericOAuth } from "better-auth/plugins";

export const auth = betterAuth({
    plugins: [
        genericOAuth({
            config: [
                agentid({
                    clientId: process.env.AGENTID_CLIENT_ID!,
                    clientSecret: process.env.AGENTID_CLIENT_SECRET!,
                }),
            ],
        }),
    ],
});

Use your existing Better Auth client, or create one. No client plugin is required:

import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient();

Start sign-in with the standard social-provider API:

await authClient.signIn.social({
    provider: "agentid",
    callbackURL: "/",
});

See the AgentID Better Auth guide for the complete setup.

Scopes and owner claims

The default scopes are openid, email, and profile. These identify the agent and expose its AgentMail address. To also request information about the human who owns the agent, add owner_profile and owner_email:

agentid({
    clientId: process.env.AGENTID_CLIENT_ID!,
    clientSecret: process.env.AGENTID_CLIENT_SECRET!,
    scopes: ["openid", "email", "profile", "owner_profile", "owner_email"],
});

Owner claims are returned by AgentID's UserInfo endpoint and are available to Better Auth callbacks in the raw OAuth profile. See the AgentID guide for an example of reading them later with the stored access token.

Protocol details

  • Discovery: https://auth.agentid.com/.well-known/openid-configuration
  • Token endpoint authentication: client_secret_basic
  • PKCE: required (S256)
  • Callback path: /api/auth/callback/agentid
  • ID tokens: verified through AgentID's discovery metadata and JWKS

AgentID does not echo an OIDC nonce in authorization-code ID tokens. The helper therefore disables Better Auth's nonce binding for this provider and requires PKCE instead. Signature, issuer, audience, algorithm, and expiry validation remain enabled.

Development

pnpm install
pnpm check

版本与发布记录

@agentmail/agentid-better-auth 共发布 2 个版本,首次发布于 2026/09/02;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.1.1latest2026/09/032 个月前
0.1.02026/09/022 个月前

关于 @agentmail/agentid-better-auth 的常见问题

@agentmail/agentid-better-auth 是什么?

AgentID provider helper for Better Auth's Generic OAuth plugin

如何安装 @agentmail/agentid-better-auth?

在项目目录运行 npm install @agentmail/agentid-better-auth,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:better-auth(>=1.7.2 <2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@agentmail/agentid-better-auth 支持 TypeScript 吗?

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

@agentmail/agentid-better-auth 支持 ESM 还是 CommonJS?

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

@agentmail/agentid-better-auth 可以商用吗?

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

@agentmail/agentid-better-auth 的下载量有多少?

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

@agentmail/agentid-better-auth 还在维护吗?

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