A minimal Fastify example showing how to protect API routes with access token validation using MonoCloud.
- MonoCloud access token validation with Fastify
- Global route protection via hooks
- Accessing the authenticated user's claims
Built with @monocloud/backend-node.
Before you begin:
- In the MonoCloud Dashboard, create a new API
- Set the Audience (for example
https://api.example.com) — this uniquely identifies your API - Add a scope named
example-apiand mark the scope as a default scope
This repo includes a .env template. Replace the placeholders with values from your API:
MONOCLOUD_BACKEND_TENANT_DOMAIN=https://<your-domain>
MONOCLOUD_BACKEND_AUDIENCE=https://<your-api-identifier>Do not commit real secrets. This file is for local development only.
npm install
npm startThe server starts on http://localhost:3000.
curl -H "Authorization: Bearer <your-access-token>" http://localhost:3000/api/protected- Fastify Quickstart: https://www.monocloud.com/docs/quickstarts/fastify-backend
- Fastify SDK Docs: https://www.monocloud.com/docs/sdks/fastify-backend
- API Reference: https://monocloud.github.io/auth-js
- Use GitHub Issues for bug reports and feature requests.
- For tenant or account-specific help, contact MonoCloud Support through your dashboard.
Do not report security issues publicly. Please follow the contact instructions at: https://www.monocloud.com/contact
Licensed under the MIT License. See the included LICENSE file.