nocobase-app-plugin-api-keys
できること
NocoBaseアプリにAPIキーによるアクセスを追加し、スクリプトや他のシステムがAPIを呼び出せるようにします。外部ツールをNocoBaseアプリに接続する開発者向けです。
使う場面
- ✓スクリプトや連携が、NocoBaseアプリのAPIを呼び出す必要があるとき。
- ✓アプリが発行したAPIキーが拒否されているとき。
- ✓特定の利用者として、その利用者のロールで動くAPIキーが必要なとき。
スキルのリンク
https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-api-keys/skills/nocobase-app-plugin-api-keys/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“毎晩実行するスクリプトがNocoBaseアプリのAPIを呼び出せるよう、APIキーによるアクセスを追加してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
AIはAPI Keysプラグインとそのデータベースのテーブルを登録します。各キーは持ち主のセッションに対応付けられ、スクリプトは持ち主のロールで動作します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
API Keys App Plugin
Use this Skill when an App needs non-interactive callers — a script, a cron job,
a third-party integration — to reach its API as a real user, or when a key the
App issued is being rejected. The default configuration resolves a key into its owner’s Session and carries that user’s roles. Applications needing scoped credentials must use a separate configuration with enableSessionForAPIKeys: false and enforce their business rules on the server.
This package is Better Auth's
API Key plugin plus the
apikey migration. apiKey is wrapped
only to supply three defaults, all overridable; its name, options and behaviour
are Better Auth's, and Better Auth's documentation applies unchanged.
Public surfaces
- Server plugin: default export of
@nocobase/app-plugin-api-keys/server. Contributes theapikeytable migration and nothing else. apiKey(options?), plusAPI_KEY_TABLE_NAME,API_KEY_ERROR_CODESand the option types, from the same entry. Use these rather than adding@better-auth/api-keyto the App: the migration here matches the schema this version declares, and taking both from one package keeps them in step.- Client registration factory:
@nocobase/app-plugin-api-keys/client. It contributes no pages. apiKeyClient, re-exported from@better-auth/api-key/clientby the same entry.ApiKeySummaryand the expiry helpers, for the App's own key management page. Such a page readsuseAuthenticationClient().apiKey, typed through the authentication plugin'sAuthClientPluginRegistry, and is declared among the App's own routes.- HTTP API:
POST /api/auth/api-key/create,GET /api/auth/api-key/list,GET /api/auth/api-key/get,POST /api/auth/api-key/update, andPOST /api/auth/api-key/delete. All five act only on the caller's own keys.
The plugin contributes no NocoBase route of its own. The endpoints above are
Better Auth's, mounted by Authentication's /api/auth/* handler. Its server registers one thing: the access check that lets a valid key read the App's API document.
Register it
Both halves are required, and each fails differently on its own.
- Add the default export to the App's
server/plugins.tsandclient/plugins.ts. - Add
apiKey()topluginsinserver/config/auth.ts, andapiKeyClient()topluginsinclient/config/auth.ts. - Run
pnpm nocobase db apply.
Only step 1 leaves the apikey table created and no endpoints mounted. Only
step 2 mounts endpoints against a table that does not exist, and every call
fails at the database.
The three defaults
apiKey() supplies enableSessionForAPIKeys: true, rateLimit: { enabled: false } and requireName: true, so an App normally passes nothing.
enableSessionForAPIKeys is the one that has to be set. Better Auth defaults
it off, and with it off a key authenticates nothing: keys are still
issued, and every request carrying one answers 401. Nothing points at the
configuration, so do not override it without meaning to.
rateLimit is off because Better Auth's own default is 10 requests per key per
day, which is a quota for issuing keys rather than for using them. Pass
{ enabled: true, maxRequests: 1000, timeWindow: 60_000 } for a quota the App
actually wants.
All three are overridable, and passing all three back reproduces Better Auth's own behaviour exactly.
Call the API with a key
curl -H 'x-api-key: <key>' https://example.com/api/orders
An App route needs no change. auth.required() and auth.optional() resolve
the key into the owner's Session, and Authorization then evaluates that user's
roles. Read context.get('auth') exactly as for a cookie Session.
Pass apiKeyHeaders: ['x-api-key', 'authorization-key'] to accept a different
header.
To find out what the App's API offers, read its OpenAPI document with the same key: GET /api/swagger returns the JSON document and GET /api/swagger/docs the Swagger UI page. A signed-in session or a valid key may read it; anything else gets 401 with error.reason API_DOCS_UNAUTHENTICATED. The API key endpoints are listed there under /api/auth/api-key/..., tagged Authentication.
What a key can reach, and what it cannot
A key is its owner, so it reaches the Better Auth endpoints a Session reaches.
Verified against @better-auth/api-key 1.7.1 with only an x-api-key header:
| Endpoint
よくある質問
スクリプトはキーをどう送りますか?
各リクエストで、x-api-keyヘッダーにキーを入れて送ります。
キーの権限を制限できますか?
初期設定では、持ち主のロールを引き継ぐため、できません。スコープ付きのキーは別の設定だと、このスキルは説明しています。
ログイン画面も追加されますか?
いいえ。APIキーによるアクセスだけを追加します。
詳細
作者による元の説明
Register the API Keys plugin in a NocoBase App, let scripts and integrations call the App's API with an x-api-key header, or work out why a key is rejected.
repo: nocobase/nocobase
人気
- GitHubのスター
- 25k
- ランキング
- #10088
- ライセンス
- —
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
nocobase-app-development
25kエージェントが、NocoBase 3の完全なビジネスアプリケーションのために、ページ、ルーティング、データ、権限、テストを作れるよう支援します。
shadcn
25kエージェントが、公式のドキュメントとレジストリを使い、Webプロジェクトの shadcn/uiコンポーネントを見つけ、追加し、修正し、スタイルを整えられるよう支援します。
nocobase-app-plugin-development
25kエージェントが、既存のNocoBase 3アプリの中で、サーバー、クライアント、データベース、登録の部分を含むプラグインを作成し、保守できるよう支援します。
nocobase-app-upgrade
25kエージェントが、NocoBaseのアプリを新しいテンプレートのリリースにアップグレードし、テンプレートの変更を取り込みつつ、あなた自身の作業を保てるよう支援します。
似ているスキル
reverse-engineer-anything
422kREAツールを使って、出荷済みのアプリやパッケージの中身を調べ、機能の説明、版の比較、再構築の手順をエージェントが支援します。
1password
394k1Password CLIをセットアップし、サインインして、秘密情報の値を会話に表示せずに読み取ったり注入したりするようエージェントを支援します。
healthcheck
394kOpenClawを動かすコンピューターやサーバーを、SSH、ファイアウォール、更新、バックアップなどのセキュリティリスクについて監査し、安全な修正案を提案するようエージェントを支援します。