Feathers Cloud Auth
Feathers Cloud Auth adds secure and scalable user authentication to any JavaScript and TypeScript web application. It works with NodeJS, Cloudflare Workers, Deno or Bun and even on websites with no server at all.
How it works
While Feathers Cloud Auth looks similar to traditional identity providers by letting users log in through a login page, it works a little different under the hood. Instead of oAuth flows and shared secrets, it uses cryptographic keys that are securely stored on each device and links them to a user identity.
The only thing needed to verify a user identity is the public application identifier. It is self contained and requires no backend, secrets or additional server requests. It even works offline.
Quick start
After you log into Feathers Cloud for the first time, you will be asked to setup your first organization and application.
Then, in any React, VueJS, Svelte, Angular etc. web application, you can install the Cloud Auth package like this:
npm i @featherscloud/auth
It is initialized like this:
import { createClient, LoginRequiredError } from '@featherscloud/auth'
const auth = createClient({
appId: '<your-app-id>'
})
Making an authenticated HTTP request to your API server, e.g. looks like this using the fetch API:
try {
// Create the authorization header for each request
const authorization = await auth.getHeader()
// Make a request to your server with the authorization header
const response = await fetch('https://api.myapp.com', {
headers: { authorization }
})
console.log(await response.json())
}
catch (error: unknown) {
// Redirect to the login page when login is required
if (error instanceof LoginRequiredError) {
window.location.href = await auth.getLoginUrl(error)
}
else {
throw error
}
}
For more details and framework examples see the client section
In a NodeJS, Deno, Bun or Cloudflare Worker API, that request can be verified like this:
import { createVerifier } from '@featherscloud/auth'
const verifier = createVerifier({
appId: '<your-app-id>'
})
const { user } = verifier.verifyHeader(request.headers.authorization)
// User has user.email, user.organization which is the Feathers Cloud Auth organization
// and user.id which is the Cloud Auth user id
For more details and complete platform spefici examples see the platforms section