Platforms
Once the Cloud Auth client is integrated into your web application, requests can be authenticated on any modern web runtime with the verifier.
Installation
When using a package manager, the @featherscloud/auth
package is installed like this:
sh
npm i @featherscloud/auth
pnpm add @featherscloud/auth
yarn add @featherscloud/auth
bun add @featherscloud/auth
Initialization
A verifier that can verify headers and access tokens is initialized like this:
ts
import { createVerifier } from '@featherscloud/auth'
const appId = '<your-app-id>'
const verifier = createVerifier({ appId })
Usage
In a web standard request handler, the verifier is used like this:
ts
async function handler(request: Request) {
try {
const header = request.headers.get('Authorization')
// Verify the Authorization header and get the user information
const { user } = await verifier.verifyHeader(header)
return Response.json(user)
}
catch (error) {
return Response.json({ error: error.message }, {
status: 400,
headers
})
}
}
Platforms
For complete server examples of each supported platform that works with the framework client examples see:
- Node and Express
- Cloudflare Workers
- Deno
- Bun