Pular para o conteúdo
Skillpedia
Segurança25 mil · #10088

nocobase-app-plugin-api-keys

O que ela faz

Esta skill adiciona acesso por chave de API a um app NocoBase, para que scripts e outros sistemas possam chamar a API dele. Ela é indicada para desenvolvedores que conectam ferramentas externas a um app NocoBase.

Quando usar

  • ✓Quando um script ou integração precisa chamar a API do seu app NocoBase.
  • ✓Quando uma chave de API emitida pelo app está sendo recusada.
  • ✓Quando você precisa de chaves de API que atuem como um usuário específico, com as funções desse usuário.

Link da skill

https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-api-keys/skills/nocobase-app-plugin-api-keys/SKILL.md

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-api-keys/skills/nocobase-app-plugin-api-keys/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Você pode adicionar acesso por chave de API ao meu app NocoBase para que meu script noturno possa chamar a API dele?”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

A IA registra o plugin API Keys e a tabela de banco de dados dele. Cada chave é associada à sessão do dono, para que o script atue com as funções desse usuário.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do 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

Perguntas frequentes

Como um script envia a chave?

Ele envia a chave no cabeçalho x-api-key em cada requisição.

Uma chave pode ter permissões limitadas?

Não com a configuração padrão, que carrega as funções do dono. A skill descreve uma configuração separada para chaves com escopo.

Ele adiciona uma página de login?

Não. Ele apenas adiciona acesso por chave de API.

Detalhes

Descrição original do autor

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

Popularidade

Estrelas no GitHub
25 mil
Posição no ranking
#10088
Licença
—
Atualizada em
02/11/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas