본문으로 건너뛰기
Skillpedia
보안25k · #10088

nocobase-app-plugin-api-keys

하는 일

이 스킬은 스크립트와 다른 시스템이 API를 호출할 수 있도록 NocoBase 앱에 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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-api-keys/skills/nocobase-app-plugin-api-keys/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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 the apikey table migration and nothing else.
  • apiKey(options?), plus API_KEY_TABLE_NAME, API_KEY_ERROR_CODES and the option types, from the same entry. Use these rather than adding @better-auth/api-key to 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/client by the same entry.
  • ApiKeySummary and the expiry helpers, for the App's own key management page. Such a page reads useAuthenticationClient().apiKey, typed through the authentication plugin's AuthClientPluginRegistry, 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, and POST /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.

  1. Add the default export to the App's server/plugins.ts and client/plugins.ts.
  2. Add apiKey() to plugins in server/config/auth.ts, and apiKeyClient() to plugins in client/config/auth.ts.
  3. 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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬