Aller au contenu
Skillpedia
Sécurité25k · #10088

nocobase-app-plugin-api-keys

Ce qu’il fait

Cette skill ajoute l'accès par clé API à une application NocoBase, pour que des scripts et d'autres systèmes puissent appeler son API. Elle s'adresse aux développeurs qui relient des outils externes à une application NocoBase.

Quand l’utiliser

  • ✓Quand un script ou une intégration doit appeler l'API de votre application NocoBase.
  • ✓Quand une clé API émise par l'application est refusée.
  • ✓Quand vous avez besoin de clés API qui agissent comme un utilisateur précis, avec ses rôles.

Lien du skill

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

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-api-keys/skills/nocobase-app-plugin-api-keys/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Je voudrais ajouter un accès par clé API à mon application NocoBase pour que mon script de nuit puisse appeler son API.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

L'IA enregistre le plugin API Keys et sa table de base de données. Chaque clé est associée à la session de son propriétaire, pour que le script agisse avec les rôles de cet utilisateur.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis 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

Questions fréquentes

Comment un script envoie-t-il la clé ?

Il l'envoie dans un en-tête x-api-key à chaque requête.

Une clé peut-elle avoir des permissions limitées ?

Pas avec la configuration par défaut, qui reprend les rôles du propriétaire. La skill décrit une configuration séparée pour les clés limitées.

Cela ajoute-t-il une page de connexion ?

Non. Cela ajoute seulement l'accès par clé API.

Détails

Description originale de l’auteur

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

Popularité

Étoiles GitHub
25k
Position au classement
#10088
Licence
—
Mis à jour
02/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires