Api authorization
Skill undp/carbon-footprint-program/.claude/skills/api-authorization
Authentication and authorization for apps/api endpoints. Use when adding or changing access control on an API route — picking the right auth/role hook and wiring it in route.ts.From its SKILL.md
npx -y skills add undp/carbon-footprint-program --skill api-authorizationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.1 KB, as published. Nobody here has run it
Authentication & Authorization
Two-dimension role model. Apply the correct decorator in route.ts:
fastify.requireAuth— onRequest hook; checks the user is authenticated. Use on all protected routes.fastify.requireRoles([SystemRole.ADMIN, ...])— onRequest hook; restricts by system-level roles (USER,ADMIN,SUPERADMIN).fastify.requireOrganizationRole(extractor, { allowedRoles, canAdminsBypass })— preHandler hook; restricts by organization-scoped roles (VIEWER,CONTRIBUTOR,ADMIN). Requires anextractorthat pulls the organization ID from the request (params/body/query).fastify.requireCarbonInventoryAccess(extractor, { requiredOrganizationRoles, canAdminsBypass })— preHandler hook; checks access to a specific carbon inventory. Supports anonymous access via thex-carbon-inventory-uuidheader, creator-only access for standalone inventories, and organization membership checks. Requires an extractor (e.g.,idRequestExtractor).fastify.requireReductionProjectAccess({ requiredOrganizationRoles, canAdminsBypass })— preHandler hook; checks access to a reduction project via organization membership. Extracts the project ID fromrequest.params.id. Supports admin bypass whencanAdminsBypassis set.
Domain-specific access hooks (requireCarbonInventoryAccess, requireReductionProjectAccess) are only for endpoints within their own domain (carbon inventory endpoints, reduction project endpoints). Endpoints in other domains that reference these entities indirectly should rely on requireOrganizationRole.
Access the current user via request.currentUser (set by the user-resolve-plugin in preHandler).
Source: apps/api/src/plugins/app/authorizationPlugin.ts, organizationAuthorizationPlugin.ts, carbonInventoryAuthorizationPlugin.ts, reductionProjectAuthorizationPlugin.ts.